Palindromize
SRM 335 · 2007-01-17 · by soul-net
Problem Statement
A palindrome is a string that reads the same from left to right as it does from right to left. Given a
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character of s will be a lowercase letter ('a'-'z').
Statement by TopCoder, Inc. — view the original on the archive.
"add" Returns: "adda"
Add 'a' to make a palindrome. "adddda" is also a valid palindrome, but it is not the shortest possible one.
"cigartragic" Returns: "cigartragic"
This is already a palindrome, so the shortest solution is to add 0 letters.
"redocpot" Returns: "redocpotopcoder"
"acaba" Returns: "acabaca"
"z" Returns: "z"
Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Palindromize with a public method string minAdds(string s) · 77 test cases · 2 s / 256 MB per case