TopcoderArchiveVisit Topcoder
SRM3 Feb 2007
SRM 337

Palindromize2

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
Palindromize2
Method:
minChanges
Parameters:
String
Returns:
String
Method signature:
String minChanges(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character of s will be a lowercase letter ('a'-'z').

Examples

  1. "ameba"
    Returns: "abeba"
    You can get "abeba" or "amema" with only 1 change. Among those two, "abeba" comes earlier alphabetically.
  2. "cigartragic"
    Returns: "cigartragic"
    The input is already a palindrome, so the best choice is to do 0 changes.
  3. "abcdef"
    Returns: "abccba"
  4. "cxbpaxz"
    Returns: "cxapaxc"
Back to all problems