I am not getting what is the error in code testcases not passing

#include <bits/stdc++.h>
using namespace std;
int main()
{
int no;
cin>>no;
int arr[no];
for(int i=0;i<no;i++)
{
cin>>arr[i];
}
int q;
cin>>q;
for(int j=0;j<q;j++)
{
int input;
cin>>input;
auto low=lower_bound(arr,arr+no,input);
auto up=upper_bound(arr,arr+no,input);
if(low==(arr+no))
{
cout<<-1;
}
else
{
cout<<(low-arr)<<" β€œ;
}
if((up==arr+no)&&(up!=arr+no-1))
{
cout<<-1;
}
else if((up==arr+no)&&(up==arr+no-1))
{
cout<<(up-arr-1)<<” β€œ;
}
else
{
cout<<(up-arr-1)<<” ";
}
cout<<endl;

}

}

Hey @aayuushh
Please paste your code on CB IDE and send it. Some code is missing here.

#include <bits/stdc++.h>
using namespace std;
int main()
{
int no;
cin>>no;
int arr[no];
for(int i=0;i<no;i++)
{
cin>>arr[i];
}
int q;
cin>>q;
for(int j=0;j<q;j++)
{
int input;
cin>>input;
auto low=lower_bound(arr,arr+no,input);
auto up=upper_bound(arr,arr+no,input);
if(low==(arr+no))
{
cout<<-1;
}
else
{
cout<<(low-arr)<<" β€œ;
}
if((up==arr+no)&&(up!=arr+no-1))
{
cout<<-1;
}
else if((up==arr+no)&&(up==arr+no-1))
{
cout<<(up-arr-1)<<” β€œ;
}
else
{
cout<<(up-arr-1)<<” ";
}
cout<<endl;

}

}

@aayuushh
Please use https://ide.codingblocks.com/

i used codingblocks ide only
please copy the code and see it is formatted

Hey @aayuushh
Please send code like this next time onwards https://ide.codingblocks.com/s/189202
And you solution is completely fine. You forgot to print space after line 22 printing -1.

If your doubt is resolved please mark it as closed.

@aayuushh
You didn’t check if index returned is of the element or not. If element is not present in array then index of another element is returned. Your second if condition for β€œup” doesn’t make sense. Please try to write your code again from scratch.