Bit Manipulation
Bit manipulation operates directly on a number's binary representation with AND, OR, XOR, and shifts to gain speed or O(1) space. XOR's self-cancelling property, bitmasks for subsets, and the 'n & (n-1)' trick are the recurring tools.
10 LeetCode problems solved with the Bit Manipulation pattern. Practice them with spaced repetition so the pattern sticks.
- Bitwise AND of Numbers RangeMEDIUM · O(log right)
- Minimum Array EndMEDIUM · O(log n + log x)
- Minimum Flips to Make a OR b Equal to cMEDIUM · O(1)
- Missing NumberEASY · O(n)
- Number of 1 BitsEASY · O(1)
- Reverse BitsEASY · O(1)
- Single NumberEASY · O(n)
- Single Number IIMEDIUM · O(n)
- Sum of All Subset XOR TotalsEASY · O(n)
- Sum of Two IntegersMEDIUM · O(1)
See the full solution
The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.
Start free →