BackmediumStrings Swiggy

Galactic Translator 2 Solution

Problem Statement

Given a string representing an alien message, encode it by shifting all vowels to the next vowel in the sequence 'aeiou' (with 'u' wrapping around to 'a') and leave consonants unchanged, then reverse the entire string to decipher the message.

Example 1
Input
hello
Output
iolmuuiae

Explanation: Step-by-step: 1. 'h' is a consonant, so it remains unchanged: h 2. 'e' is shifted to 'i': i 3. 'l' is a consonant, so it remains unchanged: l 4. 'l' is a consonant, so it remains unchanged: l 5. 'o' is shifted to 'u': u 6. 'u' wraps around to 'a': a 7. 'a' is shifted to 'e': e 8. 'e' is shifted to 'i': i 9. 'e' is shifted to 'i': i 10. The entire string is reversed to get the output 'iolmuuiae'.

Example 2
Input
orajnamilak
Output
uueaenilak

Explanation: Step-by-step: 1. 'o' is shifted to 'u': u 2. 'u' wraps around to 'a': a 3. 'r' is a consonant, so it remains unchanged: r 4. 'a' is shifted to 'e': e 5. 'j' is a consonant, so it remains unchanged: j 6. 'n' is a consonant, so it remains unchanged: n 7. 'a' is shifted to 'e': e 8. 'm' is a consonant, so it remains unchanged: m 9. 'i' is shifted to 'a': a 10. 'l' is a consonant, so it remains unchanged: l 11. 'a' is shifted to 'e': e 12. 'k' is a consonant, so it remains unchanged: k 13. The entire string is reversed to get the output 'uueaenilak'.

Constraints

  • Input string will only contain lowercase English letters.
  • Input length will not exceed 100 characters.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free