Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: For the numbers 1, 2, 3, 4, 5, how many unordered pairs (i, j) with i < j have i XOR j strictly less than 4?

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

Correct answer: D. 4

Check each pair's XOR against 4 directly. The pairs whose XOR is small share their high bits, which is why 1 and 2, 2 and 3 and similar pairs qualify.

More Coding Interview Problems questions

Exams that ask this topic