&Topic

Bit Manipulation Problems

Bit-manipulation problems — XOR tricks, masks, popcount, and integer encoding without arithmetic.

Easy · 4

Medium · 1

Bit manipulation is a niche but high-leverage interview topic. A handful of bit tricks — XOR for in-place pairing, AND with (n-1) to clear the lowest set bit, shifts for fast multiply/divide — turn problems that look like they need a hash map into one-line constant-space solutions.

The interview cluster is small and well-defined. Popcount (count set bits) — Number of 1 Bits, Counting Bits. XOR pairing (find the unique element) — Single Number, Missing Number. Bit reversal — Reverse Bits. Adder without arithmetic — Sum of Two Integers. Once you've memorized the five or six core tricks, every interview problem in this category is a quick win.

The Ratta bit-manipulation track covers Number of 1 Bits, Counting Bits, Reverse Bits, Missing Number, and Sum of Two Integers. Each problem includes the bit-level intuition (drawn out with a worked example in binary) and complete implementations in C++, Java, Python, and Go.

Browse other topics