Skip to main content
Back to Topics

Bit Manipulation Problems (284)

Problems tagged with Bit Manipulation

About Bit Manipulation

Bit Manipulation is a fundamental technique in data structures and algorithms where you directly operate on the binary representation of numbers using bitwise operators such as AND (&), OR (|), XOR (^), NOT (~), and bit shifts (<<, >>). Because these operations run in constant time and work directly at the hardware level, they often provide extremely efficient solutions to problems involving integers, sets, and binary states.

In coding interviews, bit manipulation frequently appears in problems related to unique number detection, subset generation, parity checks, and optimization tasks. Top tech companies use these questions to test a candidate's understanding of low-level computation and their ability to recognize patterns that reduce time or memory complexity. Many problems that seem complicated with traditional approaches can be solved elegantly using a few clever bit operations.

Some of the most common bit manipulation patterns include:

  • Checking, setting, clearing, or toggling a specific bit in a number
  • Using XOR to find unique elements or detect differences
  • Counting set bits (Hamming weight)
  • Using bit masks to represent subsets or states
  • Optimizing brute-force solutions by iterating through bit representations

Bit manipulation is often combined with other algorithmic techniques. For example, subset enumeration with bit masks is widely used in Backtracking problems, state compression appears in Dynamic Programming, and binary representations are closely tied to Math concepts like powers of two and parity. In some problems, you may also track frequencies or states using structures from Hash Table or process values stored in an Array.

The best way to master this topic is through practice. FleetCode provides 274 Bit Manipulation problems ranging from beginner tricks (like checking if a number is a power of two) to advanced interview challenges involving bitmask dynamic programming and optimized state transitions. By solving these systematically, you'll develop the intuition to quickly recognize when a bit-level solution can outperform a traditional algorithm.

Prerequisites

1
Math

Bit manipulation relies heavily on binary number properties such as powers of two, parity, and modular arithmetic. Understanding these mathematical foundations helps you reason about bit operations correctly.

2
Array

Many bit manipulation interview questions involve scanning arrays to find unique elements, duplicates, or patterns. Array traversal combined with XOR or bit masks is a common approach.

3
Hash Table

Hash tables are often the baseline solution for frequency tracking problems. Learning bit manipulation helps replace hash-based solutions with constant-space alternatives using XOR or bit masks.

4
Dynamic Programming

Advanced problems use bit masks to represent states in dynamic programming, especially for subset or state-compression DP where each bit represents a chosen element.

Page 3 of 6

Practice by Difficulty

Start Easy, progress to Hard.

Related Topics

Frequently appear alongside Bit Manipulation.

FAQ

Common questions about Bit Manipulation.

What is Bit Manipulation in DSA?

Bit manipulation is the technique of solving algorithmic problems by directly operating on the binary representation of integers using operators like AND, OR, XOR, and bit shifts. These operations are extremely fast and often reduce both time and space complexity compared to traditional approaches.

Is Bit Manipulation important for FAANG interviews?

Yes. While it appears less frequently than topics like arrays or dynamic programming, bit manipulation questions are common in FAANG and top tech company interviews. They are used to test logical thinking and understanding of low-level operations.

What are common Bit Manipulation patterns to learn?

Key patterns include XOR for finding unique elements, bit masking for subset representation, checking and modifying individual bits, counting set bits (Hamming weight), and using shifts to multiply or divide by powers of two.

How many Bit Manipulation problems should I practice for interviews?

Most candidates become comfortable with the topic after solving around 40–60 well-chosen problems. Practicing 100+ problems builds strong pattern recognition. FleetCode provides 274 Bit Manipulation problems covering beginner to advanced interview patterns.

What is the best way to learn Bit Manipulation for coding interviews?

Start by understanding binary numbers and bitwise operators. Then practice small problems like checking bits, detecting powers of two, and XOR tricks before moving to subset enumeration and bitmask dynamic programming. Consistent practice helps build intuition for recognizing these patterns quickly.

What are the most common Bit Manipulation problems in coding interviews?

Common interview problems include finding the single number using XOR, counting set bits, checking if a number is a power of two, generating subsets using bit masks, and solving missing or duplicate number problems. Many companies also ask problems involving bitmask dynamic programming.