#include
#include
using namespace std;
int main() {
long long int n;
cin>>n;
long long int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int t;
cin>>t;
int q[100];
for(int i=0;i<t;i++)
{
cin>>q[i];
}
for(int i=0;i<t;i++)
{ auto it=0,ut=0;
it=lower_bound(arr,arr+n,q[i])-arr;
ut=upper_bound(arr,arr+n,q[i])-arr-1;
if(it==n && ut==n-1)
{
cout<<"-1"<<" “<<”-1";
}
else{
cout<<it<<" “<<ut;
cout<<”\n";
}
}
return 0;
}
What is wrong with this code
@Kunalgoyal use map for detecting if element exists or not ur code dont take care of it
5
1 10 11 20 291
1
22
ur code gives 4 3 ans -1 -1
#include
#include
using namespace std;
int main() {
long long int n;
cin>>n;
long long int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int t;
cin>>t;
int q[100];
for(int i=0;i<t;i++)
{
cin>>q[i];
}
for(int i=0;i<t;i++)
{ auto it=0,ut=0;
it=lower_bound(arr,arr+n,q[i])-arr;
ut=upper_bound(arr,arr+n,q[i])-arr-1;
if(ut==it-1)
{
cout<<"-1"<<" “<<”-1";
}
else{
cout<<it<<" “<<ut;
cout<<”\n";
}
}
return 0;
}
i have changed it. still not working
@Kunalgoyal just print a new line after displaying -1 -1 it will work .
hope your doubt is cleared if yes dont forget to mark it as resolved 