Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many index pairs i < j in [3, 5, 6, 8, 1] satisfy a[i] + a[j] > a[i] XOR a[j]?

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

Correct answer: D. 5

a + b = (a XOR b) + 2(a AND b), so the strict inequality holds exactly when a AND b is nonzero. Testing that shared-bit condition gives the same count as the direct check.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic