Error: tle error; what should be the other approach;please brief

#include
#include
using namespace std;
class node{
public:
int data;
nodeleft;
node
right;

	node(int d){
		data=d;
		left=NULL;
		right=NULL;
	}

};

node* buildBalancedBST(int ar[],int s,int e){
//base condition
if(s>e){
return NULL;
}

//recursion condition
int m=(s+e)/2;
node* newNode=new node(ar[m]);
newNode->left=buildBalancedBST(ar,s,m-1);
newNode->right=buildBalancedBST(ar,m+1,e);

return newNode;

}

void preOrderPrint(node*root){
if(root==NULL){
return;
}
cout<data<<" ";
preOrderPrint(root->left);
preOrderPrint(root->right);

return;

}

int main() {

int t;
cin>>t;
while(t--){
	int n;
	cin>>n;

	int ar[n];

	for(int i=0;i<n;i++){
		cin>>ar[i];
	}

    sort(ar,ar+n);

	node* root=buildBalancedBST(ar,0,n-1);

    int k1,k2;
    cin>>k1;
    cin>>k2;

    cout<<"# Preorder : ";
	preOrderPrint(root);
    cout<<endl;
    int s=0,e=n-1;
    int m=(s+e)/2;
    while(ar[m]!=k1){
        if(ar[m]<k1){
            s=m+1;
        }
        else{
            e=m-1;
        }

        m=(s+e)/2;  
    }

    cout<<"# Nodes within range are : ";
    while(ar[m]!=k2){
        cout<<ar[m]<<" ";
        m++;
    }


    cout<<ar[m]<<endl;

}

}

Hey!
Please check the following code for hint:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.