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
"RADAR"
Returns: 0
From the problem statement. This is already a palindrome, so no changes are needed."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."ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA"
Returns: 0
A long string, but it's good already."APPIRIO"
Returns: 3