Getting wrong answer in this case

Can you tell me why am I getting wrong answer in this case . You can refer to my code shown below
#include<bits/stdc++.h>
using namespace std;

class Node{
public:
int data;
Node *left;
Node *right;

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

};

Node *build(int a[],int s,int e){

if(s>e){
	return NULL;
}

int mid=(s+e)/2;
Node *root = new Node(a[mid]);

root->left=build(a,s,mid-1);
root->right=build(a,mid+1,e);

return root;

}

void pre(Node * root){
if(root==NULL){
return;
}

cout<<root->data<<" ";

pre(root->left);
pre(root->right);

}
vector ans;

void specialPre(Node *root, int k1,int k2){
if(root==NULL){
return ;
}

if((root->data) >= k1 && (root->data)<= k2){
	ans.push_back(root->data);
}

specialPre(root->left,k1,k2);
specialPre(root->right,k1,k2);

}
int main(){
int t;
cin>>t;
int n,k1,k2;
while(t–){
cin>>n;
int a[n];

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

	sort(a,a+n);

	Node *root= build(a,0,n-1);
	cout<<"Preorder ";
	pre(root);

	cout<<"\nNodes within range are : ";
	cin>>k1>>k2;
	specialPre(root,k1,k2);
	int n=(k2-k1)+1;	
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<" ";
	}

}
return 0;

}

@aman.tandon3096
Instead of vector ans, write vector<int>ans;
it’s compilation error

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.