Goat Latin
Real-world version: Rook TalkThe 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:
- if its first letter is a vowel, meaning one of the letters in
aeiouin either case, leave its letters where they are; otherwise take that first letter off the front and put it on the end; - append
okto the word; - append the letter
ka furtheritimes.
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.
def to_rook_talk(sentence: str) -> str:public String toRookTalk(String sentence)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's