[ INFO ]category: Coding difficulty: medium freq: Optional first seen: 2026-03-13
[MEDIUM][CODING][OPTIONAL]
$catproblem.md
Practice/Meta/Leetcode 824. Goat Latin
Leetcode 824. Goat Latin
CodingOptional
Problem
You are building a language translation system that converts English sentences into "Sheep Language." In Sheep Language, each word is transformed according to specific rules based on whether it starts with a vowel or consonant.
Given a sentence as a string, convert it to Sheep Language using these transformation rules:
If a word begins with a vowel (a, e, i, o, u), keep the word as-is
If a word begins with a consonant, move that first letter to the end of the word
After applying the above rule, append "ma" to the end of every word
Additionally, append a number of 'a' characters equal to the word's position in the sentence (1-indexed)
The vowel check should be case-insensitive (both 'A' and 'a' are vowels), and you should preserve the original capitalization of letters.
Requirements
Split the input sentence into individual words
For each word, determine if it starts with a vowel or consonant (case-insensitive check)
Apply the consonant-moving rule if applicable
Append "ma" to each transformed word
Append a number of 'a's equal to the word's 1-based position
Reconstruct and return the transformed sentence with spaces between words
Preserve original letter casing throughout the transformation
Constraints
1 ≤ sentence.length ≤ 150
The sentence consists of English letters and spaces only
There are no leading or trailing spaces
All words in the sentence are separated by a single space
Time complexity: O(n) where n is the length of the sentence
Space complexity: O(n) for storing the result
Examples
Example 1:
`
Input: "I speak"
Output: "Imaa peaksmaaa"
Explanation:
"I" starts with vowel, keep it → "I" + "ma" + "a" = "Imaa"
"speak" starts with consonant 's', move to end → "peaks" + "ma" + "aa" = "peaksmaaa"
`