0

Find the longest palindrome I tried this, but its not working! Please help!

Solution hint Any subword of w that is a palindrome is also a subword when w is reversed. Input format The first line of the input contains a single integer N indicating the length of the word. The following line contains a single word of length N, made up of the letters a,b,…, z. Output format The first line of the output must contain a single integer indicating the length of the longest subword of the given word that is a palindrome. The second line must contain a subword that is a palindrome and which of maximum length. If there is more than one subword palindrome of maximum length, print the one that is lexicographically smallest (i.e., smallest in dictionary order). Test Data: You may assume that 1 ≤ N ≤ 5000. You may further assume that in 30% of the inputs 1 ≤ N ≤ 300. Example: We illustrate the input and output format using the above examples: Sample Input 1: 5 abbba Sample Output 1: 5 abbba Sample Input 2: 12 abcbcabbacba Sample Output 2: 8 bcabbacb https://code.sololearn.com/c8GiqAG95Qv6/?ref=app

25th Mar 2019, 1:31 PM
Roshini Manoharan
4 Réponses
0
The reason for getting an error is that you are trying to get inputs inside a loop. But sololearn interpreter takes all arguments at once. A solution is giving the words with the length N at the beginning. Kindly check your code in your machine too! Because it will allow you to give dynamic inputs
25th Mar 2019, 2:26 PM
Seniru
Seniru - avatar
0
Its not working in my device too
25th Mar 2019, 2:53 PM
Roshini Manoharan
0
Its not working in my device too
25th Mar 2019, 2:53 PM
Roshini Manoharan
0
Is there any other code available for this?
25th Mar 2019, 2:57 PM
Roshini Manoharan