# Category Archives: Bit Magic

## Count of even and odd set bit with array element after XOR with K

Given an array arr[] and a number K. The task is to find the count of the element having odd and even number of the… Read More »

## Count of even set bits between XOR of two arrays

Given two arrays A[] and B[] having N and M positive elements respectively. The task is to count the number of elements in array A… Read More »

## Minimum flips in a Binary array such that XOR of consecutive subarrays of size K have different parity

Given a binary array arr[] of length N, the task is to find the minimum flips required in the array such that XOR of a… Read More »

## Number of integers in a range [L, R] which are divisible by exactly K of it’s digits

Given a range of values [L, R] and a value K, the task is to count the numbers in the given range which are divisible… Read More »

## Check if a Number is Odd or Even using Bitwise Operators

Given a number N, the task is to check whether the number is even or odd using Bitwise Operators. Examples: Input: N = 11 Output:… Read More »

## Bitwise OR( | ) of all even number from 1 to N

Given a number N, the task is to find the bitwise OR( | ) of all even number from 1 to N. Examples: Input: 2… Read More »

## Bitwise AND of all the odd numbers from 1 to N

Given an integer N, the task is to find the bitwise AND (&) of all the odd integers from the range [1, N]. Examples: Input:… Read More »

## Find Kth smallest value for b such that a + b = a | b

Given a number a and k, the task is to find the k’th smallest value for b such that a + b = a |… Read More »

## Construct XOR tree by Given leaf nodes of Perfect Binary Tree

Given the leaf nodes of a perfect binary tree, the task is to construct the XOR tree and print the root node of this tree.… Read More »

## Generating N-bit Grey Code starting from K

Given a value N and K, the task is to generate N-bits Gray Code starting from the value K. Examples: Input: N = 2, K… Read More »

## Check if all bits can be made same by flipping two consecutive bits

Given a binary string, the task is to find whether all the digits of the string can be made equal i.e either 0 or 1… Read More »

## Maximize distance between any two consecutive 1’s after flipping M 0’s

Given the size of a binary array consisting of 0’s only as n and an integer m which is the number of flips allowed from… Read More »

## Find the sum of power of bit count raised to the power B

Given an integer, array A. Find the sum of set bits raised to the power A[i] for each element in A[i]. Example: Input: N =… Read More »

## Maximum XOR value of maximum and second maximum element among all possible subarrays

Given an array arr[] of N distinct positive integers, let’s denote max(i, j) and secondMax(i, j) as the maximum and the second maximum element of… Read More »

## Append two elements to make the array satisfy the given condition

Given an array arr[] of non-negative integers, let’s define X as the XOR of all the array elements and S as the sum of all… Read More »