All problems
0713EasyString

Rook Talk

Tracked in this browser only
Write code

Trains the technique from

LeetCode 824Goat Latin

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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