Show problems as
Classic problem #824EasyString

Goat Latin

Real-world version: Rook Talk
Tracked in this browser only
Read Goat Latin on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Children at a playground trade messages in a word game called Rook Talk. A sentence is rewritten one word at a time, and the rewritten words stay in their original order, separated by single spaces.

Take the word sitting in position i, counting the first word as position 1, and apply these steps in order:

  1. if its first letter is a vowel, meaning one of the letters in aeiou in either case, leave its letters where they are; otherwise take that first letter off the front and put it on the end;
  2. append ok to the word;
  3. append the letter k a further i times.

Letter case is never altered: a letter that arrives uppercase stays uppercase wherever it ends up.

Return the rewritten sentence.

Examples

Example 1

Input
sentence = "wren and heron"
Output
"renwokk andokkk eronhokkkk"

`wren` does not start with a vowel, so it becomes `renw`, then `ok`, then one k: `renwokk`. `and` starts with a vowel and keeps its letters, then `ok` and two k's: `andokkk`. `heron` becomes `eronh`, then `ok` and three k's: `eronhokkkk`.

Example 2

Input
sentence = "Zebra crossing"
Output
"ebraZokk rossingcokkk"

`Zebra` does not start with a vowel, so the capital `Z` moves to the end and stays capital, giving `ebraZ`, then `ok` and one k. `crossing` becomes `rossingc`, then `ok` and two k's.

Example 3

Input
sentence = "Otter"
Output
"Otterokk"

`Otter` begins with an uppercase vowel, so its letters stay put, and `ok` plus one k is appended.

Constraints

  • 1 <= sentence.length <= 150
  • sentence consists of English letters and spaces only.
  • sentence has no leading or trailing space, and consecutive words are separated by a single space.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def to_rook_talk(sentence: str) -> str:
Java
public String toRookTalk(String sentence)