Wednesday, 1 Dec 2021
Category: setBitCount

#include using namespace std;  void precompute(vector& v){        for (long long i = 0; i < 64; i++) {                for (long long j = i + 1; j < 64; j++) {                        for (long long k = j + 1; k < 64; k++) {                                                  long long int x                    = (1LL

import java.io.*;import java.lang.*;import java.util.*;class GFG{static int makeEqual(int arr[], int n){             int fre0[] = new int[33];        int fre1[] = new int[33];        for(int i = 0; i < n; i++)    {        int x = arr[i];                for(int j = 0; j < 33; j++)        {                        if ((x & 1) != 0)            {                                                 fre1[j] += 1;            }                        else            {                                                 fre0[j] += 1;            }                        x = x >> 1;        }    }        int ans = 0;        for(int i = 0; i […]

#include using namespace std;  int prefixCount[32][10000];  void findPrefixCount(vector arr,                     int size){        for (int i = 0; i < 32; i++) {                          prefixCount[i][0]            = ((arr[0] >> i) & 1);                          for (int j = 1; j < size; j++) {                          prefixCount[i][j]                = ((arr[j] >> i) & 1);            prefixCount[i][j]                += prefixCount[i][j – 1];        }    }}  void arrayBitwiseAND(int size){        int result = 0;          for (int i = 0; i < 32; i++) {                          int temp = […]

Check if Bitwise AND of concatenation of diagonals exceeds that of middle row/column elements of a Binary MatrixGiven a binary matrix mat[][] of dimensions N * N, the task is to check if Bitwise AND of the decimal numbers obtained by concatenating primary and secondary diagonals elements is greater than the Bitwise AND of the […]

Count of pairs {X, Y} from an array such that sum of count of set bits in X ⊕ Y and twice the count of set bits in X & Y is M Given an array arr[] consisting of N non-negative integers and an integer M, the task is to find the count of unordered […]