Problem Statement
To make a Mountain Palindrome from a given String you must sort the String's characters in ascending order and then append the fewest number of characters required for it to be a palindrome. A palindrome is a string that is the same backwards as forwards. For example, "ABCCBA", "DEED", and "RADAR" are all palindromes.
Create a class MountainP that contains the method makeMP, which takes a String before and returns a String that is the generated Mountain Palindrome.
Definition
- Class:
- MountainP
- Method:
- makeMP
- Parameters:
- String
- Returns:
- String
- Method signature:
- String makeMP(String before)
- (be sure your method is public)
Notes
- Remember to append the FEWEST number of characters required to produce a palindrome.
Constraints
- before will have between 1 and 25 characters, inclusive.
- before will only contain capital letters ('A'-'Z').
Examples
"BEFORESTRING"
Returns: "BEEFGINORRSTSRRONIGFEEB"
First we sort: "BEEFGINORRST" Next we append the fewest number of characters required to produce a palindrome."AZZAZ"
Returns: "AAZZZAA"
First we sort: "AAZZZ" Next we append the fewest number of characters required to produce a palindrome."PROGRAMMING"
Returns: "AGGIMMNOPRRPONMMIGGA"
"ABRACADABRA"
Returns: "AAAAABBCDRRDCBBAAAAA"
"CINDERELLA"
Returns: "ACDEEILLNRNLLIEEDCA"
"A"
Returns: "A"
"AB"
Returns: "ABA"