Ctrl K

Vowels in Code Order

Medium
You are given a string word of English letters. The vowels are a, e, i, o, u in either case; every other letter is a consonant. Rearrange the vowels so that, reading left to right, they appear in non-decreasing order of their ASCII codes (so every uppercase vowel comes before every lowercase one). Each consonant must stay in its position. Return the resulting string.
Example 1
word="rObOtIcs" → 'rIbOtOcs'

The vowels O, O, I sit at positions 1, 3 and 5. In code order they are I, O, O; the consonants stay where they were.

Example 2
word="banAnE" → 'bAnEna'

The vowels are a, A and E. Uppercase letters come before lowercase ones in ASCII, so the order is A, E, a.

Example 3
word="Rhythm" → 'Rhythm'
Constraints
  • 1 ≤ len(word) ≤ 10⁵
  • word consists only of uppercase and lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAnagram Buckets MediumBiggest Number From Pieces MediumCharacters Grouped by Count MediumA Subsequence of One Word Only MediumLongest Word by Crossing Out Medium
loading Python…
Input
word="rObOtIcs"
Expected
'rIbOtOcs'

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