Data Structures & AlgorithmsModerateTCS NQT Digital · CAT

Problem: The bitwise AND of all integers from 12 to 15 inclusive is computed. What is the result?

  1. A. 15
  2. B. 0
  3. C. 12
  4. D. 8

Correct answer: C. 12

All four share the prefix 11 and differ in the low two bits, so the AND keeps 1100 = 12. OR gives 15, XOR of 12..15 gives 0, and keeping only the top bit gives 8.

More Coding Interview Problems questions

Exams that ask this topic