Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Compute the longest palindromic prefix of "abacabacaba" (the longest prefix that reads the same backwards). What is its length?

  1. A. 7
  2. B. 3
  3. C. 11
  4. D. 1

Correct answer: C. 11

"abacabacaba" equals its reverse, so the whole string of length 11 is the answer. Looking only at proper prefixes gives "abacaba" (7), stopping at "aba" gives 3, and 1 is a single letter.

More Coding Interview Problems questions

Exams that ask this topic