What is wrong in this code , it is showing TLE and wrong answer , but in my compiler its working

public class Main {

public static void main(String[] args) {

	Scanner sc=new Scanner(System.in);
	
	int n=sc.nextInt();
	int pre[]=new int[n];
	for(int i=0 ; i<n ; i++)
		pre[i]=sc.nextInt();
	
	int in[]=new int[n];
	for(int i=0 ; i<n ; i++)
		in[i]=sc.nextInt();
	
	BinaryTree4 bt = new BinaryTree4(pre , in);
	
	System.out.println(bt.isBST());
	
}

}

class BinaryTree4 {

private class Node {
	int data;
	int size=0;
	Node left;
	Node right;
	
	Node(){
		
	}
	
	Node(int data , Node left , Node right){
		this.data=data;
		this.left=left;
		this.right=right;
	}
}

private Node root=null;
	
BinaryTree4(int [] pre , int [] in){
	this.root=pre_in_generate(pre , 0 , pre.length-1 , in , 0 , in.length-1);
}

private Node pre_in_generate(int [] pre , int preS , int preE , int [] in , int inS , int inE) {
	
	if(preS>preE || inS>inE)
		return null;

	int i=inS;
	while(i<inE) {
		if(pre[preS]==in[i])
			break;
		i++;
	}
	
	Node curr = new Node();
	
	curr.data = in[i];
	
	curr.left = pre_in_generate(pre , preS+1 , preS+i , in , inS , i-1);
	
	curr.right = pre_in_generate(pre , preS+i+1 , preE , in , i+1 , inE);
	
	if(curr.left!=null && curr.right!=null)
		curr.size=curr.left.size + curr.right.size + 1;
	else if(curr.left==null && curr.right!=null)
		curr.size=curr.right.size+1;
	else if(curr.left!=null && curr.right==null)
		curr.size=curr.left.size+1;
	else
		curr.size=1;
	
	
	return curr;
}

private int maxsize=0;
public int isBST() { 
	this.isBST(this.root , Integer.MIN_VALUE , Integer.MAX_VALUE);
	return maxsize;
}
private boolean isBST(Node node , int min , int max) {

	if(node==null) return true;
	
	boolean self=true;
	if(node.data<min || node.data>max) 
		self = false;
	boolean left = isBST(node.left , min , node.data);
	boolean right = isBST(node.right , node.data , max);
	
	if(left && right) {
		if(maxsize<node.size)
			maxsize=node.size;
	}
	
	return (left && right && self)? true : false ;
	
}

}

Hey @Himanshu-Jhawar-2273952536067590
try for this input :
9
50 30 5 20 60 45 70 65 80
5 30 20 50 45 60 65 70 80
correct output : 5
your code gives 1
your are doing wrong