Reverse Vowels of a String

Easy

Description

Given a string s, reverse only all the vowels in the string and return it. The vowels are "a", "e", "i", "o", and "u", and they can appear in both lower and upper case.

Examples

Input:s = "hello"
Output:"holle"
Explanation:

e and o are swapped.

Input:s = "programming"
Output:prigrammong
Explanation:

The vowels are o, a, i (from left to right). After reversing their positions, i goes to position 2, a goes to position 6, and o goes to position 10.

Input:s = "AEIOU"
Output:UOIEA
Explanation:

All characters are vowels (uppercase), so reversing the vowels is equivalent to reversing the entire string. A and U swap, E and O swap, while I stays in the middle.

Constraints

  • 1 ≤ s.length ≤ 3 × 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!