Count of pairs whose bitwise AND is a power of 2 O(n) code example
Example: Count of pairs whose bitwise AND is a power of 2 O(n)
long countPairs(const vector& arr) {
long ans=0;
int mx=0;
map mp;
for(int ai : arr){
mp[ai]++;
mx = max(mx,ai);
}
for(int i=0; i<=mx; ++i){
if(!mp.count(i)) continue;
for(int j=i; j<=mx; ++j){
if(!mp.count(j)) continue;
// cout<