Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

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

Correct answer: D. 3

XOR with a value can decrease it only when the highest set bit of a[j] is set in a[i]. Checking the pairs directly on this small array is quickest.

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

Exams that ask this topic