Corrected Code.Still test cases showing wrong

#include<bits/stdc++.h>
using namespace std;

void Search(int *A,int n,int x)
{
int first=0;
int last=0;
auto lb=lower_bound(A,A+n,x);
first=lb-A;

if(first==n)
   cout<<-1<<" ";

else
   cout<<first<<" ";

auto ub=upper_bound(A,A+n,x);
last=(ub-A)-1;
if(ub==A+n && A[last]!=x)
{
    cout<<-1;
}
else
   cout<<last;

}

int main()
{
int n,i,x;
cin>>n;
int *A=new int[n];
for(i=0;i<n;i++)
cin>>A[i];
int q;
cin>>q;
while(q>0)
{
cin>>x;
Search(A,n,x);
cout<<endl;
q–;
}

}

hi @Mukul-Shane-1247687648773500 ,
check this https://ide.codingblocks.com/s/655872, ive updated your code and commented

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.