# Tag Archives: Bit Algorithms

## Find all powers of 2 less than or equal to a given number

Given a positive number N, the task is to find out all the perfect powers of two which are less than or equal to the… 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 »

## Count of subsets not containing adjacent elements

Given an array arr[] of N integers, the task is to find the count of all the subsets which do not contain adjacent elements from… Read More »

## Reverse bytes of a Hexadecimal Number

Given an unsigned integer N. The task is to reverse all bytes of N without using a temporary variable and print the reversed number. Examples:… Read More »

## Find array such that no subarray has xor zero or Y

Given two integers X (1 ≤ X ≤ 15) and Y. The task is to find an array of the maximum possible length N such… Read More »

## Minimum Bitwise OR operations to make any two array elements equal

Given an array arr[] of integers and an integer K, we can perform the Bitwise OR operation between any array element and K any number… Read More »

## Smallest number greater or equals to N such that it has no odd positioned bit set

Given an integer N, the task is to find the smallest integer X such that it has no odd position set and X ≥ N.… Read More »

## Count of numbers whose 0th and Nth bits are set

Given a positive integer N, the task is to count the numbers that can be represented with N bits and whose 0th and Nth bits… Read More »

## Minimize the number of steps required to reach the end of the array

Given an integer array arr[] of length N consisting of positive integers, the task is to minimize the number of steps required to reach the… Read More »

## Print steps to make a number in form of 2^X – 1

Given a number N, there are two steps to be performed. At odd step, XOR the number with any 2^M-1, where M is chosen by… Read More »

## Check if matrix A can be converted to B by changing parity of corner elements of any submatrix

Given two binary matrices A[][] and B[][] of N X M. In a single operation, one can choose a sub-matrix (min of 2 rows and… Read More »

## Find the value at kth position in the generated array

Given three integer n, m and k. Find the element at kth position after repeating the given operation n number of times. In a single… Read More »

## Total distinct pairs from two arrays such that second number can be obtained by inverting bits of first

Given two arrays arr1[] and arr2[], the task is to take an element from first array (say a) and one element from second array (say… Read More »

## Minimum number of elements that should be removed to make the array good

Given an array arr[], the task is to find the minimum number of elements that must be removed to make the array good. A sequence… Read More »

## Find a positive number M such that gcd(N^M, N&M) is maximum

Given a number N, the task is to find a positive number M such that gcd(N^M, N&M) is the maximum possible and M < N.… Read More »