##
Extract ‘k’ bits from a given position in a number.
August 21, 2017

How to extract ‘k’ bits from a given position ‘p’ in a number? Examples: Input : number = 171 k = 5 p = 2… Read More »

August 21, 2017

How to extract ‘k’ bits from a given position ‘p’ in a number? Examples: Input : number = 171 k = 5 p = 2… Read More »

Implement a space efficient algorithm to check First repeated character in a string without using any additional data structure in one traversal. Use additional data… Read More »

August 15, 2017

Given a number, change all bits at even positions to 0. Examples: Input : 30 Output : 10 Binary representation of 11110. Bits at Even… Read More »

August 9, 2017

Prerequisites : INT_MAX and INT_MIN in C/C++ and Applications. Arithmetic shift vs Logical shift Suppose you have a 32-bit system : The INT_MAX would be… Read More »

August 4, 2017

Given an array, write a program to add the minimum number(should be greater than 0) to the array so that the sum of array becomes… Read More »

August 3, 2017

A number N is given. We need to print its ‘K’th Least Significant Bit. Examples: Input : num = 10, k = 4 Output :… Read More »

Following are not allowed to use 1) Comparison Operators 2) String functions Examples: Input : num1 = 1233, num2 – 1233 Output : Same Input… Read More »

August 1, 2017

You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i… Read More »

July 31, 2017

Given a positive number you need to check whether it’s complement and the number are anagrams or not. Examples: Input : a = 4294967295 Output… Read More »

July 27, 2017

Given a number n, our task is to find all 1 to n bit numbers with no consecutive 1s in their binary representation. Examples: Input… Read More »

July 23, 2017

Given a number n. Find sum of all number upto n whose 2 bits are set. Examples: Input : 10 Output : 33 3 +… Read More »

July 18, 2017

Given a number maximize it by swapping bits at it’s extreme positions i.e. at first and last position, second and second last position and so… Read More »

July 17, 2017

Given two non-negative numbers n and m. The problem is to find the smallest number having n number of set bits and m number of… Read More »

July 13, 2017

Given a non-negative number n. Find the position of rightmost unset bit in the binary representation of n, considering the last bit at position 1,… Read More »

July 12, 2017

The Problem This problem is named after Flavius Josephus a Jewish historian who fought against the Romans. According to Josephus him and his group of… Read More »