Bit Manipulation
Use AND, OR, XOR, and shifts to solve problems directly on the binary representation of numbers, often in O(1) space.
Bit Manipulation Practice Problems
Easy
7 problems- 118easy
Single Number
Find the one number in an array that does not appear exactly twice.
- 119easy
Number of 1 Bits
Count how many bits are set to 1 in the binary form of a number.
- 120easy
Counting Bits
For every number up to n, count how many bits are set to 1 in its binary form.
- 121easy
Missing Number
Find the one number missing from a list containing n distinct numbers from 0 to n.
- 122easy
Reverse Bits
Reverse the bits of a 32-bit unsigned integer.
- 271easy
Power of Two
Check whether an integer is a power of two using a bit trick.
- 272easy
Hamming Distance
Count the number of differing bits between two integers.
Medium
4 problems- 123medium
Single Number II
Find the one number in an array that does not appear exactly three times.
- 124medium
Sum of Two Integers
Add two integers together without using the + or - operators.
- 125medium
Bitwise AND of Numbers Range
Compute the bitwise AND of every number in a range from m to n.
- 273medium
Single Number III
Find the two numbers that appear exactly once in an array where every other number appears twice.
Hard
1 problemsRelated concepts
| Topic | Description |
|---|---|
| Sliding Window | Solve fixed-window problems: maximum sum of k elements, moving averages, and O(n) updates as the window slides. |
| Two Pointers | Scan a sorted array or string from both ends at once to find pairs, remove duplicates, or reverse data in O(n). |
| Binary Search | Cut a sorted range in half on every step to find a value or boundary in O(log n) instead of checking one by one. |
| Depth-First Search | Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids. |
| Breadth-First Search | Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph. |
| Dynamic Programming | Break a problem into overlapping subproblems and reuse their answers to avoid recomputing the same work. |