Reverse Vowels of a String

Given a string s, reverse only the vowels in it and return the result. The vowels are 'a', 'e', 'i', 'o' and 'u', in lower or upper case, and they can appear more than once. All other characters stay where they are.

30:00

Reverse Vowels of a String
easy
Free written solution
Topics
Companies

Given a string s, reverse only the vowels in it and return the result. The vowels are 'a', 'e', 'i', 'o' and 'u', in lower or upper case, and they can appear more than once. All other characters stay where they are.

Example 1:
Input: {"s":"IceCreAm"}
Output: AceCreIm
Constraints:
  • 1≤s.length≤3×1051 \leq s.\text{length} \leq 3 \times 10^5

  • s consists of printable ASCII characters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"IceCreAm"}

Mark the vowels a, e, i, o, u in both cases. Only these 4 characters will trade places.

vowel
L = left
R = right
#n = swapped pair

chars (8)

I

0

c

1

e

2

C

3

r

4

e

5

A

6

m

7

vowels, left to right

before

I
e
e
A

now

I
e
e
A
Variables
VariableValue
n8
vowels4
DepthFunction Call
Stack empty
0/8