Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many ordered pairs (i, j) with 1 ≤ i < j ≤ 10 satisfy i XOR j = 3?

  1. A. 5
  2. B. 3
  3. C. 6
  4. D. 4

Correct answer: D. 4

Test every pair with i < j for XOR equal to 3. Pairs must differ in exactly the bits of 3 after cancellation, so counting pairs with i + j = 3 is a different condition.

More Coding Interview Problems questions

Exams that ask this topic