When to Use

Pattern triggers

Look for these signals in the problem:

  • "Single number" among pairs: XOR cancels paired numbers, leaving the single one.
  • "Power of 22" check: n & (n-1) equals 00 only for powers of 22.
  • "Count bits" or Hamming operations: Bit counting techniques like Brian Kernighan's algorithm.
  • "Subset" enumeration with bitmask: Each bit represents inclusion/exclusion of an element.
  • "No extra space" constraint: Bit manipulation often achieves O(1)O(1) space where other approaches need O(n)O(n).