Help Rahul To Search

test case 0 is showing wrong answer

#include
#include
using namespace std;

int main(){

int n;
cin>>n;
int a[n];

for(int i = 0; i < n; i++){
    cin>>a[i];
}
int key;
cin>>key;

int *p = find(a,a+n,key);
bool present = binary_search(a,a+n,key);

if(present == true){
    cout<<p-a<<endl;
}
else{
    cout<<"-1";
}


return 0;

}

hi @karanaggarwal708_71435e604edb5689
dont use binary search array is not sorted
instead do

long long *p = find(a,a+n,key);

    if(p-a != n){
        cout<<p-a<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }

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.