pls see below code and point out error,it is not printing -1 -1 for input which is not present in array.
#include
using namespace std;
int main()
{
int n,s,l,q;
int flag=1;
int arr[q],a[n];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
cin>>q;
for(int i=0;i<q;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(arr[i]==a[j])
{
s=j;
flag=0;
cout<< s << " ";
break;
}
}
for(int j=n-1;j>=0;j--)
{
if(arr[i]==a[j])
{
flag=0;
l=j;
cout<< l << endl;
break;
}
}
if(flag==1){
cout<<"-1 -1";
}
}
return 0;
}