Brian Kernighan’s Algorithm to count set bits in an integer
Given an integer, count its set bits using the Brian Kernighan’s algorithm.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven an integer, count its set bits using the Brian Kernighan’s algorithm.
Given a number, check if adjacent bits are set in the binary representation of it.
Find the total number of bits needed to be flipped to convert a given integer to another.
Check if the binary representation of a number is palindrome or not.
Given an integer, compute its absolute value (abs) without branching.
This post will discuss some bit hacks/tricks on letters of the English alphabet. 1. Convert uppercase character to lowercase, 2. Convert lowercase character to uppercase, 3. Invert alphabet’s case, 4. Find a letter’s position in alphabet.
This post will discuss a few related problems related to unsetting the rightmost set bit of a number.
This post will discuss a few related problems that operate on the k’th bit of a number. 1. Turn off k’th bit in a number, 2. Turn on k’th bit in a number, 3. Check if k’th bit is set for a number, 4. Toggle the k’th bit.
In this post, we will see how to 1. Check if an integer is even or odd, 2. Detect if two integers have opposite signs or not, 3. Add one to an integer, 4. Swap two numbers without using any third variable.
Given two integers, x and n, where n is non-negative, efficiently compute the power function pow(x, n) using Divide & Conquer.
Given a sorted binary array, efficiently find the total number of 1’s in it.
Given a sorted integer array, find the floor and ceil of a given number in it. The floor and ceil map the given number to the largest previous or the smallest following integer.