Ctrl K

Mirror the Vowels

Easy
You are given a string text. The vowels are the letters a, e, i, o and u in either case. Reverse the order of all the vowels in the string: the first vowel trades places with the last, the second with the second to last, and so on. All other characters keep their positions, and each vowel keeps its own case as it moves. Return the resulting string.
Example 1
text='Orange juice' → 'eringu jeacO'

The vowels in order are O a e u i e. Reversed they are e i u e a O, placed back into the same slots: eringu jeacO.

Example 2
text='rhythm' → 'rhythm'

There are no vowels, so the string stays the same.

Example 3
text='aUtO' → 'OUta'

The vowels a U O become O U a; the consonant t stays put: OUta.

Constraints
  • 1 ≤ text.length ≤ 3 · 10⁵
  • text consists of printable ASCII characters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWhere the Fragment Starts EasyMirror Phrase Check EasySame When Flipped EasyFlip the Characters in Place EasyHidden in Order Easy
loading Python…
Input
text='Orange juice'
Expected
'eringu jeacO'

Run checks the first 3 tests in your browser. Submit checks all 5 tests on the server, hidden ones included.