# Category Archives: Bit Magic

## Minimum XOR of OR and AND of any pair in the Array

Given an array arr[] of N positive integers the task is to find the minimum value of Bitwise XOR of Bitwise OR and AND of… Read More »

## Maximize XOR subsequence possible by equidistant elements from both ends

Given an array A[] of size N, find the Maximum Xor Subsequence such that both A [ i ] and A [ N – i… Read More »

## Powers of 2 to required sum using Bit Masking

Given an integer N, the task is to find the numbers which when added after being raised to the Power of 2 gives the integer… Read More »

## Absolute difference between set and unset bit count in N

Prerequisite: Bitset function in STL library Given a number N, the task is to find the absolute difference of the number of set and unset… Read More »

## Number of ways to change the Array such that largest element is LCM of array

Given an array arr[], the task is to count the number of the unique arrays can be formed by updating the elements of the given… Read More »

## Number formed by flipping all bits to the left of rightmost set bit

Given an integer N, the task is to flip all the bits to the left of rightmost set bit and print the number generated.Examples: Input:… Read More »

## Find array sum using Bitwise OR after splitting given array in two halves after K circular shifts

Given an array A[] of length N, where N is an even number, the task is to answer Q independent queries where each query consists… Read More »

## Find position of given term in a series formed with only digits 4 and 7 allowed

There is a series of numbers that have only digits, 4 and 7, and numbers are arranged in increasing order. The first few numbers of… Read More »

## Minimum flips required to form given binary string where every flip changes all bits to its right as well

Given a string S, the task is to find minimum flips required to convert an initial binary string consisting of only zeroes to S where… Read More »

## Count of subarrays of size K with elements having even frequencies

Given an Array arr[] and an integer K, the task is to count subarrays of size K in which every element appears even number of… Read More »

## Maximum number of 0s that can be flipped such that Array has no adjacent 1s

Given a binary array arr, the task is to find the maximum number of 0s that can be flipped such that the array has no… Read More »

## Partition of a set into K subsets with equal sum using BitMask and DP

Given an integer array arr[] of consisting of N integers, the task is check if it is possible to divide the given array into K… Read More »

## Count of pairs from Array with sum equal to twice their bitwise AND

Given an array arr[], the task is to count the pairs in the array with sum equal to twice their bitwise AND, i.e., Examples: Input:… Read More »

## Sum of bit differences for numbers from 0 to N

Given a number N, the task is to calculate the total number of corresponding different bit in the binary representation for every consecutive number from… Read More »

## std::unary_negate() in C++ with Examples

The std::unary_negate() is a wrapper function object returning the complement of the unary predicate it holds. A wrapper function is a subroutine in a software… Read More »