#824

Goat Latin

pupil · 355 · lc easy +23 · verified · 69.9% accepted · 1,029 likes · top 78%

Description

Given a string sentence made up of space-separated words (each word contains only letters), convert it to "Goat Latin" according to the following rules:

- If a word starts with a vowel ('a', 'e', 'i', 'o', or 'u'), append "ma" to it.

- For example, "apple" becomes "applema".

- If a word starts with a consonant, remove the first letter, append it to the end, then append "ma".

- For example, "goat" becomes "oatgma".

- Append one additional 'a' for each word's position (1-indexed) in the sentence.

- The first word gets one "a" appended, the second gets "aa", and so on.

Return the fully converted sentence.

Example 1:

Input: sentence = "I speak Goat Latin"
Output: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"

Example 2:

Input: sentence = "The quick brown fox jumped over the lazy dog"
Output: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"

Code

1
2
3