Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A string of length 4 over {0, 1} has an even number of 1s. How many such strings are palindromes?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: C. 4

Palindromes of length 4 are determined by their first two characters, giving four candidates; of these, the ones with an even number of 1s are 0000, 0110, 1001 and 1111, which yields four strings.

More Coding Interview Problems questions

Exams that ask this topic