DSA Master › Topic 17

Bit Manipulation

Bit tricks give O(1) space answers to some problems. XOR cancels matching pairs, x & (x − 1) clears the lowest set bit, and shifts let you read or set individual bits.

Concepts

How to recognise it

Common pitfalls

Problems

  1. Single Number (Easy)
  2. Number of 1 Bits (Easy)
  3. Counting Bits (Easy)
  4. Reverse Bits (Easy)
  5. Sum of Two Integers (Medium)