Find upper and lower bound-run time error

code: #include
using namespace std;

int upper(int a[],int n,int x){
int s=0;
int e=n-1;
int ans=-1;
while(s<=e){
int mid=(s+e)/2;
if(a[mid]==x){
ans=mid;
s=mid+1;
}
else if(a[mid]>x){ //change
e=mid-1;
}
else{
s=mid+1;
}
}
return ans;
}

int lower(int a[],int n,int x){
int s=0;
int e=n-1;
int ans=-1;
while(s<=e){
int mid=(s+e)/2;
if(a[mid]==x)
{
ans=mid;
e=mid-1;
}
else if(a[mid]>x){ //change
e=mid-1;
}
else{
s=mid+1;
}
}
return ans;
}

int main()
{
int n;
cin>>n;
int a[100];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int t;
cin>>t;
while(t>0)
{
int x;
cin>>x;
cout<<lower(a,n,x)<<" "<<upper(a,n,x)<<endl;
t–;
}
return 0;
}

Hey @vashishthkuntal.gajjar2019
Just increase ur array size

int a[100000];

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.

where is the solution?

Hello @vashishthkuntal.gajjar2019 you can see this :
i have marked the mistake though he has already provided you the solution.


if you have any doubt you can ask here:
Happy Learning!!

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.