TopcoderArchive
Archive
Algorithm problem

FixPalindrome

Problem statement, definition, constraints, and public examples.

Problem Statement

A palindrome is a string that reads the same forwards and in reverse. So, "EYE" and "RADAR" are palindromes, but "CAT" and "COBOL" are not.

Given a String s, return the minimum number of letters that would need to be changed in order to make the string into a palindrome.

Definition

Class:
FixPalindrome
Method:
fewestChanges
Parameters:
String
Returns:
int
Method signature:
int fewestChanges(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 capital letter ('A'-'Z').

Examples

  1. "RADAR"
    Returns: 0
    From the problem statement. This is already a palindrome, so no changes are needed.
  2. "COBOL"
    Returns: 1
    Also from the problem statement. If we change the final 'L' to a 'C', then we would have a palindrome, so one change is all that is needed.
  3. "ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA"
    Returns: 0
    A long string, but it's good already.
  4. "APPIRIO"
    Returns: 3
Back to all problems