CCC '16 J3 - Hidden Palindrome

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

A palindrome is a word which is the same when read forwards as it is when read backwards. For example, mom and anna are two palindromes.

A word which has just one letter, such as a, is also a palindrome.

Given a word, what is the longest palindrome that is contained in the word? That is, what is the longest palindrome that we can obtain, if we are allowed to delete characters from the beginning and/or the end of the string?

Input Specification

The input will consist of one line, containing a sequence of at least 1 and at most 40 lowercase letters.

Output Specification

Output the total number of letters of the longest palindrome contained in the input word.

Sample Input 1


Output for Sample Input 1


Explanation for Output for Sample Input 1

The palindrome anana has 5 letters.

Sample Input 2


Output for Sample Input 2


Explanation for Output for Sample Input 2

The palindromes aca and ada have 3 letters, and there are no other palindromes in the input which are longer.

Sample Input 3


Output for Sample Input 3



  • -2
    alihu264  commented on May 19, 2020, 2:17 a.m.

    spent 20 minutes realizing that I forgot how substrings in c++ work

  • -1
    MegaIVSB  commented on Nov. 15, 2019, 12:33 a.m.

    Can anyone tell me the answer lol

  • 15
    lele  commented on Dec. 30, 2018, 8:06 p.m.

    Tacocat is a palindrome

  • -6
    HenryJava  commented on Sept. 8, 2018, 11:22 a.m.

    This comment is hidden due to too much negative feedback. Click here to view it.

  • 2
    Multi0508  commented on Sept. 8, 2018, 10:30 a.m. edited

    this is pretty fun