04. Bit Manipulation
π§ Bit Manipulation Strategy
- XOR Properties: \(A \oplus A = 0\) and \(A \oplus 0 = A\). Use this to cancel out duplicates.
- Check Bit:
(n & (1 << i))checks if the \(i\)-th bit is set. - Set/Unset: Use
|to set a bit,& ~to unset it. - n & (n-1): Removes the last set bit (Brian Kernighanβs algorithm).
π’ Basics & Counting
π‘ XOR & Unique Elements
π΄ Advanced Logic
- Different Bits Sum Pairwise
- Count Total Set Bits
- Divide Integers
- Strange Equality
- Maximum Satisfaction