ARRREM - Editorial

Oh wait

This doesnt explain line 96

We do not need to check for all the values of k.
We can calculate the bitwise OR of the entire array and then check the lowest bit which is zero, This bit can never become one with the given numbers, so we can just remove all numbers which are bigger than this, as their addition will lead to a gap in the Bitwise OR

1 Like

I see so many issues here. The tests are probably weak. Still, it doesn’t make sense considering only the first 32 elements of the array getting accepted. :skull:

Is my code logically correct or it only passes because of the testcases?

#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define DEBUG(x...) { cout << "(" << #x << ")" << " = ( "; Print(x); }
template <typename T1> void Print(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void Print(T1 t1, T2... t2) { cout << t1 << " , "; Print(t2...); }

void solve()
{
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    int ans=0;
    int index=0;
    sort(a.begin(),a.end());
    for(int i=1;i<=n;i++)
    {
        ans|=a[i];
        
        if(((ans+1)&ans)==0)
        {
            index=i;
           


        }
    }
    cout<<n-index<<endl;
}

int main()
{
    int tests;
    cin>>tests;
    while(tests--)
    {
        solve();
    }
    return 0;
}

Thanks buddy that helped :smiley: