Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many integers from 1 to 50 inclusive have no two adjacent 1-bits in binary?

  1. A. 21
  2. B. 20
  3. C. 19
  4. D. 25

Correct answer: B. 20

x AND (x shifted right by one) is nonzero exactly when two adjacent bits are both 1, so count x where that AND is zero. Fibonacci-style counting over bit strings gives the same answer.

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

Exams that ask this topic