Generate an array with the set bit count of each index
Given a positive number n
, construct an integer array of length n
where each index stores the count of 1’s in the binary representation of the index.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a positive number n
, construct an integer array of length n
where each index stores the count of 1’s in the binary representation of the index.
Given two integers, return the Hamming distance between the two. The Hamming distance is the total number of places where the corresponding bits are different in the binary representation of two integers.
Given a limited range array of size n
and containing elements between 1 and n+1
with one element missing, find the missing number without using any extra space.
Compute modulus division of a positive number n by another positive number d which is a power of 2 without using division or modulo operator.
This post will discuss a few related problems that can be solved without using multiplication and division operators.
Given a positive integer n
and k
, perform a circular shift on the binary representation of n
by k
positions.
Print binary representation of a given number in C, C++, Java, and Python using built-in methods and custom routines.
Given an integer, reverse its bits using binary operators and lookup table in linear time.
Given an array of n
integers where every element appears an even number of times except one element, which appears an odd number of times, find that odd occurring element in logarithmic time and constant space.
Given an integer, swap adjacent bits of it. In other words, swap bits present at even positions with those present in odd positions.
Given a set S
, generate all distinct subsets of it, i.e., find a distinct power set of set S
. A power set of any set S
is the set of all subsets of S
, including the empty set and S
itself.
Given an integer array, duplicates appear in it an even number of times except for two elements, which appear an odd number of times. Find both odd appearing elements without using any extra memory.