Goat Latin - Problem

Welcome to the whimsical world of Goat Latin - a playful language transformation game! Your mission is to convert regular English sentences into this silly made-up language that follows specific phonetic rules.

The Rules:

  • Rule 1 (Vowel Words): If a word starts with a vowel (a, e, i, o, u), simply append "ma" to the end.
    Example: "apple" โ†’ "applema"
  • Rule 2 (Consonant Words): If a word starts with a consonant, move the first letter to the end, then append "ma".
    Example: "goat" โ†’ "oatgma"
  • Rule 3 (Position Suffix): Add 'a' letters based on the word's position: 1st word gets "a", 2nd word gets "aa", 3rd gets "aaa", etc.

Example: "I speak Goat Latin" becomes "Imaa eakspaaaa oatGmaaaaa atinLmaaaaaaa"

Given a sentence with words separated by spaces, return the complete Goat Latin transformation!

Input & Output

example_1.py โ€” Basic Transformation
$ Input: sentence = "I speak Goat Latin"
โ€บ Output: "Imaa eakspaaaa oatGmaaaaa atinLmaaaaaaa"
๐Ÿ’ก Note: Word 1: 'I' starts with vowel โ†’ 'I' + 'ma' + 'a' = 'Imaa'. Word 2: 'speak' starts with 's' โ†’ 'peak' + 's' + 'ma' + 'aa' = 'eakspaaaa'. Word 3: 'Goat' starts with 'G' โ†’ 'oat' + 'G' + 'ma' + 'aaa' = 'oatGmaaaaa'. Word 4: 'Latin' starts with 'L' โ†’ 'atin' + 'L' + 'ma' + 'aaaa' = 'atinLmaaaaaaa'.
example_2.py โ€” Mixed Cases
$ Input: sentence = "The quick brown fox"
โ€บ Output: "heTmaa ickquaaaa ownbrmaaaaa oxfmaaaaaaa"
๐Ÿ’ก Note: All words start with consonants: 'The' โ†’ 'heTmaa', 'quick' โ†’ 'ickquaaaa', 'brown' โ†’ 'ownbrmaaaaa', 'fox' โ†’ 'oxfmaaaaaaa'. Position-based 'a' characters increase for each word.
example_3.py โ€” Single Vowel Word
$ Input: sentence = "apple"
โ€บ Output: "applemaa"
๐Ÿ’ก Note: Single word 'apple' starts with vowel 'a' โ†’ keep as 'apple' + 'ma' + 'a' (position 1) = 'applemaa'.

Constraints

  • 1 โ‰ค sentence.length โ‰ค 150
  • sentence consists of English letters and spaces
  • sentence has no leading or trailing spaces
  • All words in sentence are separated by single spaces
  • Each word consists of lowercase and uppercase letters only

Visualization

Tap to expand
๐Ÿญ Goat Latin Assembly LineInput Sentence"I speak Goat"IspeakGoatVโœ“VowelCโœ—ConsonantCโœ—ConsonantImapeaksmaoatGmaImaa+a(1)peaksmaaa+aa(2)oatGmaaa+aaa(3)Final Result"Imaa peaksmaaa oatGmaaa"SplitDetectTransformPositionJoin๐ŸŽฏ Station FunctionsStation 1: Word Splitting | Station 2: Vowel/Consonant Check | Station 3: Rule Application | Station 4: Position Suffix | Station 5: Final Assembly
Understanding the Visualization
1
Word Intake
Split the sentence and feed each word into the assembly line
2
Vowel Detection
Scanner checks if word starts with vowel (a,e,i,o,u) or consonant
3
Transformation Station
Apply rule: vowels get 'ma' appended, consonants get first letter moved to end plus 'ma'
4
Position Stamper
Add 'a' characters based on word's position in the sentence
5
Final Assembly
Join all transformed words back into the final Goat Latin sentence
Key Takeaway
๐ŸŽฏ Key Insight: Each word transformation is independent and can be processed sequentially. The three-step process (vowel check โ†’ rule application โ†’ position suffix) creates a simple yet complete language transformation system.
Asked in
Google 15 Facebook 12 Apple 8 Microsoft 6
21.8K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen