Problem Statement
You are given a String spell containing an ancient magic spell. The spell is encrypted, but the cypher is quite simple. To decrypt the spell, you need to find all occurrences of the letters 'A' and 'Z', and then reverse their order. For example, if the encrypted spell is "AABZCADZA", you would first find all the 'A's and 'Z's: "AA_Z_A_ZA". You would then reverse their order: "AZ_A_Z_AA". The final decrypted spell is "AZBACZDAA". Return the decrypted version of the given spell.
Definition
- Class:
- MagicSpell
- Method:
- fixTheSpell
- Parameters:
- String
- Returns:
- String
- Method signature:
- String fixTheSpell(String spell)
- (be sure your method is public)
Constraints
- spell will contain between 1 and 50 uppercase letters ('A'-'Z'), inclusive.
Examples
"AZ"
Returns: "ZA"
This spell contains only letters 'A' and 'Z', so we just need to reverse it."ABACADA"
Returns: "ABACADA"
This spell remains the same after decryption."AABZCADZA"
Returns: "AZBACZDAA"
The example from the problem statement."AZBASGHNAZAHBNVZZGGGAGGZAZ"
Returns: "ZABZSGHNAZZHBNVAZGGGAGGAZA"