/345. Reverse Vowels in String

345. Reverse Vowels in String

Easy
Two Pointers60.8% acceptance

Given a string input_str, reverse the order of all vowels (a, e, i, o, u, both uppercase and lowercase) in input_str. Non-vowel characters remain in their original positions. Return the resulting string.

Example 1

Input: Programming

Output: Prigrammong

Explanation: Vowels are [o, a, i], reversed to [i, a, o], result is Prigrammong.

Example 2

Input: HELLOworld

Output: HOLLEwerld

Explanation: Vowels are [E, O, o], reversed to [o, O, E], result is HOLLEwerld.

Constraints

  • 1 <= len(input_str) <= 300000
  • input_str consists of printable ASCII characters
Python (current runtime)

Case 1

Input: 'DataScience'

Expected: 'DetaScienca'

Case 2

Input: 'AbCdEfGhIj'

Expected: 'IbCdEfGhAj'

Case 3

Input: 'xyz'

Expected: 'xyz'

Case 4

Input: 'AEIOUaeiou'

Expected: 'uoieaUOIEA'

Case 5

Input: 'Python3.8'

Expected: 'Python3.8'