TORONTO KIDS COMPUTER CLUB | Aurora Saturday 18:30 Python Homework 11.30.
16778
post-template-default,single,single-post,postid-16778,single-format-standard,ajax_fade,page_not_loaded,,no_animation_on_touch,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Aurora Saturday 18:30 Python Homework 11.30.

03 Dec Aurora Saturday 18:30 Python Homework 11.30.

Problem Description
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
banana

Output for Sample Input 1
5

Explanation for Output for Sample Input 1
The palindrome anana has 5 letters.


Sample Input 2
abracadabra

Output for Sample Input 2
3

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
abba

Output for Sample Input 3
4


Hint:
Given a string example: letters = “necessary”, you can use slice of the list to get part of the string, for example:

letters[1:4] is “ece”
or
letters[3:0:-1] will read letters backwards, but you can also get “ece”

No Comments

Sorry, the comment form is closed at this time.