Skills101
← All coding problems

Reverse the Vowels

easyStrings II+10 XPTime limit 2s

Reverse the order of only the vowels in a line of text (a e i o u, upper or lower case), keeping every other character exactly where it is. hello world becomes hollo werld, and Education becomes odicatuEn (the vowels E u a i o are written back as o i a u E).

Input: one line of text (letters, digits, spaces and punctuation; it does not start or end with a space).

Output: the line with its vowels in reverse order.

Constraints: 1 ≤ length ≤ 10⁵.

Think about it: two pointers, one at each end. Move each pointer inward until it sits on a vowel, swap the two vowels, and continue until the pointers meet.

Sample input 1

hello world

Sample output 1

hollo werld

Sample input 2

Education

Sample output 2

odicatuEn

Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).

Loading editor…

Log in to run and submit your code — it's free.