My issue
cannot able to find why it is getting wrong answer tle is fine but why wrong answer can anyone explain?
My code
#include <iostream>
using namespace std;
bool check(int arr[],int ind,int b,int req){
//base case
// if(ind==0){
// // if(b==req) return true;
// // if(b&arr[0]==req) return true;
// // else
// // return false;
// if(ind<0){
// }
// }
if(ind<0){
if(b==req) return true;
return false;
}
//recursive call
bool notTake=check(arr,ind-1,b,req);
bool take=check(arr,ind-1,b&arr[ind],req);
return notTake||take;
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int n,b;
cin>>n>>b;
int arr[n];
for(int i=0;i<n;i++) cin>>arr[i];
int ind=n-1,req=b;
bool find= check(arr,ind,b,req);
if(find==true) cout<<"yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
Problem Link: CS2023_PON Problem - CodeChef