Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many integers from 1 to 64 inclusive have a binary representation (without leading zeros) that reads the same forwards and backwards?

  1. A. 15
  2. B. 13
  3. C. 36
  4. D. 14

Correct answer: D. 14

Binary palindromes of length L: 2^(ceil(L/2) - 1) of them. Summing over lengths 1 to 6 gives 1+1+2+2+4+4 with 64 included as length 7 being not a palindrome.

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

Exams that ask this topic