For this Question: Find out the maximum sum of all keys of each sub- tree which is also a Binary Search Tree. Given a binary tree root.

Assume a BST is defined as follows:
 Only nodes with keys smaller than the node's key are found in the left subtree of a node.
 Only nodes with keys bigger than the node's key are found in the right subtree of a node.
 Both the left and right subtrees must also be binary search trees.<b>User Task:</b>
Since this will be a functional problem. You don't have to take input. You just have to complete the function <b>maxSumBST()</b> that takes head of Linked List as parameter.

Constraints:
 1<= no of nodes <= 10000
 -10000<=Node.val<=10000Any sub-tree that is also a Binary Search Tree should return the maximum sum of all keys (BST).Sample Input:
1 4 3 2 4 2 5 null null null null null null 4 6

Sample Output:
20

Explanation:
 1
 / \
 4 3
 / \ / \
 2 4 2 5
 / \
 4 6
Maximum sum in a valid Binary search tree is obtained in root node with key equal to 3., I have written this Solution Code: class Solution {
    int maxSum = 0;
    public int maxSumBST(TreeNode root) {
        if(root == null) return 0;
        check(root);
        return maxSum;
    }
    class Info{
        boolean isBST;
        int min;
        int max;
        int sum_so_far;

        public Info(boolean isBST, int min, int max, int sum_so_far){
            this.isBST = isBST;
            this.min = min;
            this.max = max;
            this.sum_so_far = sum_so_far;
        }
    }
    public Info check(TreeNode root){
        if(root == null) return new Info(true, Integer.MAX_VALUE,Integer.MIN_VALUE, 0);

        Info l = check(root.left);
        Info r = check(root.right);

        if(l == null || r == null) return null;

        if(l.max >= root.val || r.min <= root.val) return null;

        maxSum = Math.max(root.val + l.sum_so_far + r.sum_so_far, maxSum);

        return new Info(true, Math.min(root.val, l.min), Math.max(root.val, r.max), root.val                        + l.sum_so_far + r.sum_so_far);
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?