My issue
The input
2
37 11
gives output 1 , i.e removing the element 37 but this output is wrong as the bitwise or is still not equal to 2^x-1.
The solution for this should be to check the bitwise or after removing an element, in which case time complexity would be O(n^2) which would exceed the time limit.
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> h(100, 0);
vector<int> a;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
int c = 0;
a.push_back(x);
while (x > 0) {
if (x % 2 != 0) {
h[c]++;
}
x = x >> 1;
c++;
}
}
int c = 0;
for (int i = 0; i < h.size(); i++) {
if (h[i] == 0) break;
c++;
}
int ans = n;
for (int i = 0; i < n; i++) {
if (a[i] <= pow(2, c)) ans--;
}
cout << ans << endl;
}
return 0;
}
Problem Link: Array Removal Practice Coding Problem