Connection Status:
Competition Arena > Palindromize
SRM 335 · 2007-01-17 · by soul-net · Greedy, Search
Class Name: Palindromize
Return Type: String
Method Name: minAdds
Arg Types: (string)
Problem Statement

Problem Statement

A palindrome is a string that reads the same from left to right as it does from right to left. Given a String s, return the shortest palindrome that can be produced by adding zero or more characters to the right end of s. There is always one unique answer.

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character of s will be a lowercase letter ('a'-'z').
Examples
0)
"add"
Returns: "adda"

Add 'a' to make a palindrome. "adddda" is also a valid palindrome, but it is not the shortest possible one.

1)
"cigartragic"
Returns: "cigartragic"

This is already a palindrome, so the shortest solution is to add 0 letters.

2)
"redocpot"
Returns: "redocpotopcoder"
3)
"acaba"
Returns: "acabaca"
4)
"z"
Returns: "z"

Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

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

Submitting as anonymous