Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many non-empty prefixes of "abacaba" are palindromes?

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

Correct answer: B. 3

Check each prefix against its reverse; a, aba, abacaba are palindromes, while ab, abac and so on are not. The count of prefixes passing the test is the answer.

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

Exams that ask this topic