public static Value checkBST(TreeNode root) {
    if (root == null) return new Value(Integer.MAX_VALUE, Integer.MIN_VALUE);

    Value left = checkBST(root.leftChild);
    if (left == null) return null;

    Value right = checkBST(root.rightChild);
    if (right == null) return null;

    if (root.data < left.max || root.data >= right.min) return null;

    int min = Math.min(root.data, left.min);
    int max = Math.max(root.data, right.max);
    return new Value(min, max);
  }