Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: How many integers n with 1 ≤ n ≤ 100 have a binary representation that reads the same forwards and backwards?

  1. A. 18
  2. B. 22
  3. C. 19
  4. D. 50

Correct answer: C. 19

Binary palindromes up to 100 are 1, 3, 5, 7, 9, 15, 17, 21, 27, 31, 33, 45, 51, 63, 65, 73, 85, 93, 99: 19. Testing decimal palindromes instead gives 18, extending to 127 gives 22, and 50 counts all odd numbers (every binary palindrome is odd, but not conversely).

More Coding Interview Problems questions

Exams that ask this topic