@@ -0,0 +1,1893 @@
+package coding4fun;%0A%0A/**%0A * Checks is a given tree is a valid binary search tree.%0A *%0A * %3Cpre%3E%0A * Input:%0A *   10%0A *  /  %5C%0A * 5   15%0A *    /  %5C%0A *   11    20%0A * Output: true%0A *%0A * Input:%0A *    10%0A *  /  %5C%0A * 5   15%0A *    /  %5C%0A *   6    20%0A * Output: false%0A * %3C/pre%3E%0A */%0Apublic class Problem38 %7B%0A    private static class Node %7B%0A        private final int value;%0A        private Node left;%0A        private Node right;%0A%0A        private Node(int value) %7B%0A            this.value = value;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return Integer.toString(value);%0A        %7D%0A    %7D%0A%0A    private static boolean isBST(Node root) %7B%0A        return isBST(root, new PrevNode(Integer.MIN_VALUE));%0A    %7D%0A%0A    private static class PrevNode %7B%0A        private int value;%0A%0A        private PrevNode(int value) %7B%0A            this.value = value;%0A        %7D%0A    %7D%0A%0A    private static boolean isBST(Node node, PrevNode prev) %7B%0A        if (node == null) %7B%0A            return true;%0A        %7D%0A        boolean a = isBST(node.left, prev);%0A        if (prev.value %3E node.value) %7B%0A            return false;%0A        %7D%0A        prev.value = node.value;%0A        boolean b = isBST(node.right, prev);%0A        return a & b;%0A    %7D%0A%0A    private static Node createTree1() %7B%0A        Node root = new Node(10);%0A        root.left = new Node(5);%0A        root.right = new Node(15);%0A        root.right.left = new Node(11);%0A        root.right.right = new Node(20);%0A%0A        return root;%0A    %7D%0A%0A    private static Node createTree2() %7B%0A        Node root = new Node(10);%0A        root.left = new Node(5);%0A        root.right = new Node(15);%0A        root.right.left = new Node(6);%0A        root.right.right = new Node(20);%0A%0A        return root;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(isBST(createTree1())); // true%0A        System.out.println(isBST(createTree2())); // false%0A    %7D%0A%7D%0A

Add problem 38