Solution to Validate Binary Search Tree Problem.

class Solution {
    public boolean isValidBST(TreeNode root) {        
        return isValidBST(root, null, null);      
    }
    
    private boolean isValidBST(TreeNode node, TreeNode min, TreeNode max) {
        if(node == null)
            return true;
        
        if(min != null && node.val <= min.val || max != null && node.val >= max.val) {
            return false;
        }
        
        return isValidBST(node.left, min, node) && isValidBST(node.right, node, max);
    }
}