## Calculate the number of set bits for every number from 0 to N

Given a non-negative integer N, the task is to find the count of set bits for every number from 0 to N. Examples: Input: N… Read More »

## Count number of steps to cover a distance if steps can be taken in powers of 2

Given a distance K to cover, the task is to find the minimum steps required to cover the distance if steps can be taken in… Read More »

## Count total set bits in all numbers from 1 to N | Set 3

Given a positive integer N, the task is to count the total number of set bits in binary representation of all the numbers from 1… Read More »

## Find the Majority Element | Set 3 (Bit Magic)

Pre-requisite: Majority Element, Majority Element | Set-2 (Hashing) Given an array of size N, find the majority element. The majority element is the element that… Read More »

## Count Set-bits of number using Recursion

Given a number N. The task is to find the number of set bits in its binary representation using recursion. Examples: Input : 21 Output… Read More »

## Count total set bits in all numbers from 1 to n | Set 2

Given a positive integer N, the task is to count the sum of the number of set bits in the binary representation of all the… Read More »

## Number formed by the rightmost set bit in N

Given an integer N, the task is to find an integer M formed by taking the rightmost set bit in N i.e. the only set… 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 »

## Find a number containing N – 1 set bits at even positions from the right

Given a positive integer N, the task is to find a number which contains (N – 1) set bits in its binary form at every… Read More »

## Count pairs with set bits sum equal to K

Given an array arr[] and an integer K, the task is to count the pairs whose sum of set bits is K Examples: Input: arr[]… Read More »

## Count pairs of elements such that number of set bits in their OR is B[i]

Given two arrays A[] and B[] of N elements each. The task is to find the number of index pairs (i, j) such that i… Read More »

## Find the node whose sum with X has minimum set bits

Given a tree, and the weights of all the nodes and an integer x, the task is to find a node i such that weight[i]… Read More »

## Find the node whose sum with X has maximum set bits

Given a tree, and the weights of all the nodes and an integer x, the task is to find a node i such that weight[i]… Read More »

## Sort an array according to count of set bits | Set 2

Given an array arr[] of positive integers, the task is to sort the array in decreasing order of count of set bits in binary representations… Read More »

## Total character pairs from two strings, with equal number of set bits in their ascii value

Given two strings s1 and s2. The task is to take one character from first string and one character from second string and check if… Read More »