Help me in solving CS2023_PON problem

My issue

single element of an array can also be called as its subsequence then why it is giving NO on test case [1,3,5] n=3 b=2; it should be yes?

My code

#include <bits/stdc++.h>
using namespace std;

#define ll long long
int main() {
	
	int t;
	cin>>t;
	while(t--)
	{
	    ll n,b;
	    cin>>n;
	   // vector<ll> v;
	   int flag =0;
	   for(ll i =0;  i<n ;i++)
	   {
	       ll x;
	       cin>>x;
	       
	       if((x & b)==b && flag==0)
	       {
	           cout<<"YES"<<"\n";
	           flag=1;
	           //break;
	           
	       }
	   }
	   
	   if(flag==0)
	   {
	       cout<<"NO"<<"\n";
	   }
	    
	    
	}
	// your code goes here
	return 0;
}

Problem Link: CS2023_PON Problem - CodeChef

For starters, the variable b in your code is not initialized. Forgetting to read a value in can really give confusing results. I hope that one you read the correct values into the correct variables, that you will be able to fix the remaining issues.

1 Like

After correcting it . It is giving same wrong output

Yes, it does because the solution is not yet complete.
A tricky test case is B=1 with an array containing the elements 7 11 13. This case should return YES, because 7 & 11 & 13 == 1. You have to make sure that such cases are handled.