Connection Status:
Competition Arena > Palindromize2
SRM 337 · 2007-02-03 · by soul-net · Greedy, Search
Class Name: Palindromize2
Return Type: String
Method Name: minChanges
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 a palindrome that is produced by changing the minimum possible number of characters in s. Changing a character means replacing it with any single character at the same position. You are not allowed to remove or add any characters. If there are multiple answers, return the one that comes first alphabetically.

Constraints

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

You can get "abeba" or "amema" with only 1 change. Among those two, "abeba" comes earlier alphabetically.

1)
"cigartragic"
Returns: "cigartragic"

The input is already a palindrome, so the best choice is to do 0 changes.

2)
"abcdef"
Returns: "abccba"
3)
"cxbpaxz"
Returns: "cxapaxc"
4)
"z"
Returns: "z"

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

Coding Area

Language: C++17 · define a public class Palindromize2 with a public method string minChanges(string s) · 63 test cases · 2 s / 256 MB per case

Submitting as anonymous