Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: In the string "xyxyxy", how many substrings of length 4 are palindromes?

  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 3

Correct answer: B. 0

Every length-4 window of an alternating string starts and ends with different letters (x...y or y...x), so none is a palindrome and the count is zero.

More Coding Interview Problems questions

Exams that ask this topic