Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional

Among [5, 3, 6, 12, 9, 10, 1], choose two different elements. What is the largest possible value of x OR y?

  1. A. 8
  2. B. 14
  3. C. 16
  4. D. 15

Correct answer: D. 15

Bits contribute to OR whenever either number has them, so a pair with a high top bit combined with another high bit maximises the result. The maximum over all pairs is found by brute force; AND and XOR maximise different quantities.

More Coding Interview Problems questions

Exams that ask this topic