For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree.
The second line of input contains n integers, the values of the nodes of the tree.
The third line of the input contains an integer, denoting the root node of the tree.
Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child)

Constraints
1 <= n <= 50000
0 <= l, r <= n (0 denotes no child)
1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input
5
10 3 9 2 1 
4
3 0
0 0
2 0
5 1
0 0

Sample Output 
YES, I have written this Solution Code: import java.io.*;
import java.util.*;

class Main {
   static class TreeNode{
    int data;
    TreeNode left;
    TreeNode right;
    public TreeNode(int data){
        this.data = data;
    }
}
    static int max = Integer.MIN_VALUE;
    static int min = Integer.MAX_VALUE;
    static boolean isBST = true;
    static boolean isBSTUtil(TreeNode root, int min, int max){
        if(root == null) return true;
        if(root.data > max || root.data < min){
            return false;
        }
        return isBSTUtil(root.left, min, root.data) && isBSTUtil(root.right, root.data, max);
    }
    static void inorder(TreeNode root){
        if (root != null){
            inorder(root.left);
            if(root.data < min) min = root.data;
            if(root.data > max) max = root.data;
            inorder(root.right);
        }
    }
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int [] arr = new int[n];
        String [] str = br.readLine().split(" ");
        for(int i = 0; i < str.length; i++){
            arr[i] = Integer.parseInt(str[i]);
        }
        int root = Integer.parseInt(br.readLine());
        TreeNode [] tree = new TreeNode[n];
        for(int i = 0; i < n; i++){
            tree[i] = new TreeNode(arr[i]);
        }
        for(int i = 0; i < n; i++){
            String [] in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            if(l != 0)
                tree[i].left = tree[l - 1];
            if(r != 0)
                tree[i].right = tree[r - 1];
        }
        inorder(tree[root - 1]);
        System.out.println(isBSTUtil(tree[root - 1], min, max) == true ? "YES" : "NO");
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?