public boolean isValidBST(TreeNode root) {
        if (root == null) return true;
        List<Integer> prOrder = new ArrayList<>(); // hashset is more appropriate actually
        dfs(root, prOrder);
        TreeNode x = null;
        for (Integer i : prOrder)
            x = insert(x, i);
        return isTheSameTree(x, root);
    }
Solution 1:
solution one building valid bst from preorder traversal of input tree and check if they are the same
src/problems/medium/ValidateBinarySearchTree.java