Given two integers N and K, the task is to find the count of binary strings of at most N length that can be formed such that the count of consecutive 1‘s is always a multiple of K.Example:Input: N = 3, K = 2Output: 6Explanation: Binary strings of atmost N length containing consecutive 1’s as […]

Continue ReadingGiven 3 integers A, B, C, the task is to find the maximum XOR value of three number selected one from each range [0, A], [0, B], [0, C] respectively.Example: Input: A = 1, B = 2, C = 4Output: 7Explanation: Maximum XOR can be calculated by selecting 1 (from [0, 1]), 2 (from [0, 2]) […]

Continue Reading#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

Continue Reading#include using namespace std; int xorSumOfArray(int arr[], int n, int k, int count[]){ int sum = 0; int p = 1; for (int i = 0; i < 31; i++) { int val = 0; if ((k & (1

Continue ReadingProduct of count of set bits present in binary representations of elements in an arrayGiven an array arr[] consisting of N integers, the task is to find the product of the count of set bits in the binary representation of every array element.Examples:Input: arr[] = {3, 2, 4, 1, 5}Output: 4Explanation:Binary representation of the array […]

Continue Readingimport 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 […]

Continue Reading#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 = […]

Continue ReadingCheck 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 […]

Continue ReadingCount 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 […]

Continue ReadingSum of array elements whose count of set bits are unique Given an array arr[] consisting of N positive integers, the task is to find the sum of all array elements having a distinct count of set bits in the array. Examples: Input: arr[] = {8, 3, 7, 5, 3}Output: 15Explanation:The count of set bits […]

Continue Reading