Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional

How many integers x with 1 <= x <= 64 have a binary representation (without leading zeros) that reads the same forwards and backwards?

  1. A. 16
  2. B. 13
  3. C. 32
  4. D. 14

Correct answer: D. 14

A palindrome of length L is fixed by its first ceil(L/2) bits, so lengths 1 to 6 give 1 + 1 + 2 + 2 + 4 + 4 = 14 palindromes. The number 64 (1000000) is not a palindrome, and no 7-bit palindrome is at most 64.

More Coding Interview Problems questions

Exams that ask this topic