EPALIN - Extend to Palindrome
Your task is, given an integer N, to make a palindrome (word that reads the same when you reverse it) of length at least N (1 <= N <= 100,000). Any palindrome will do.
Easy, isn't it? That's what you thought before you passed it on to your inexperienced team-mate. When the contest is almost over, you find out that that problem still isn't solved. The problem with the code is that the strings generated are often not palindromic. There's not enough time to start again from scratch or to debug his messy code.
Seeing that the situation is desperate, you decide to simply write some additional code that takes the output and adds just enough extra characters to it to make it a palindrome and hope for the best. Your solution should take as its input a string and produce the smallest palindrome that can be formed by adding zero or more characters at its end. The input string will consist of only upper and lower case letters.
Example
Input: aaaa abba amanaplanacanal xyz Output: aaaa abba amanaplanacanalpanama xyzyxNote: 1. All palindromes are considered case-sensitive (i.e. 'Aa' is not a palindrome). 2. Large I/O. Be careful in certain languages.
hide comments
Krishna Mohan:
2017-11-18 06:30:32
@babur Yes. |
|
babur:
2017-06-03 08:05:09
Has anyone solved this using Z algorithm??
|
|
vengatesh15:
2017-01-23 12:55:35
AC in 1 go :-) |
|
kanishkajoshi:
2016-04-13 13:33:11
be carefull while taking input .... run code till EOF (end of file)
|
|
newbie:
2016-04-01 16:16:49
amazing concept of kmp!!! |
|
minhthai:
2016-02-01 07:23:55
anyone solve this using java? |
|
pvanit1217:
2015-10-30 21:04:49
Can anyone help me with this code <snip>. Im getting WA Last edit: 2022-07-04 23:07:52 |
|
satya_jha123:
2015-08-28 19:59:23
THERE IS AN EDITORIAL AVAILABLE FOR THIS PROBLEM ON QUORA SO IF ANYONE FINDS THIS TO BE DIFFICULT YOU CAN USE IT
|
|
scarmiglione:
2015-08-20 13:28:37
I really dont get whats wrong with this one, it gives me "wrong answer" yet the example goes through just fine ffs Last edit: 2015-08-20 13:29:01 |
|
abdelkarim:
2015-07-26 03:25:13
@arjundabra EOF |
Added by: | Muntasir Azam Khan |
Date: | 2009-03-22 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO |
Resource: | Own problem, used in Next Generation Contest 5 |