120. Burrow Speak
Kids invent a secret language called Burrow Speak. A sentence consists of English words separated by single spaces. Transform each word like this, using its position i in the sentence, counted from 1: if the word starts with a vowel (a, e, i, o, u, in either case), append wo to it; otherwise move its first letter to the end and append ow. Finally append the letter z exactly i times. Letter case is never changed.
Return the transformed sentence with single spaces between words.
Example 1
- Input:
- sentence = "I like tunnels"
- Output:
- "Iwoz ikelowzz unnelstowzzz"
- Explanation:
I starts with a vowel and is word 1: Iwoz. like moves l to the end: ikelow, plus zz. tunnels gives unnelstow plus zzz.
Example 2
- Input:
- sentence = "Eat pie"
- Output:
- "Eatwoz iepowzz"
- Explanation:
Eat starts with a vowel: Eatwoz. pie becomes iepow followed by two z letters.
Constraints
1 ≤ sentence.length ≤ 104
sentence contains English letters and single spaces, with no leading or trailing space
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(n + w^2)
- Space
- O(n + w^2)