Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

How many subsets of {1, 2, 3, ..., 12} have XOR equal to 0? The empty subset counts, because its XOR is 0.

  1. A. 256
  2. B. 255
  3. C. 260
  4. D. 128

Correct answer: A. 256

Track the count of each achievable XOR value with a DP over the elements, where each element joins or skips the subset. The empty subset is one of the counted subsets, so dropping it gives the off-by-one trap.

More Coding Interview Problems questions

Exams that ask this topic