Skip to content

04. Bit Manipulation

🧠 Bit Manipulation Strategy

  1. XOR Properties: \(A \oplus A = 0\) and \(A \oplus 0 = A\). Use this to cancel out duplicates.
  2. Check Bit: (n & (1 << i)) checks if the \(i\)-th bit is set.
  3. Set/Unset: Use | to set a bit, & ~ to unset it.
  4. n & (n-1): Removes the last set bit (Brian Kernighan’s algorithm).

🟒 Basics & Counting

🟑 XOR & Unique Elements

πŸ”΄ Advanced Logic