Problem
You get a string s. Reverse the order of the vowels in s and return the new string. All other characters stay in their places.
The vowels are a, e, i, o and u, in lowercase or uppercase. A vowel can appear more than one time.
Example 1
- Input:
- s = "rainbow"
- Output:
- "roinbaw"
- Explanation:
- The vowels are
a,iando. In the new string, they appear in the ordero,i,a.
Example 2
- Input:
- s = "Umbrella"
- Output:
- "ambrellU"
- Explanation:
- The first vowel
Uand the last vowelachange places. A vowel keeps its case when it moves.
Example 3
- Input:
- s = "xyz"
- Output:
- "xyz"
- Explanation:
- The string has no vowels, so it does not change.
Constraints
- 1 <= s.length <= 3 * 10^5
- s has printable ASCII characters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Existence of a Substring in a String and Its Reverse
Coding
- Remove Vowels from a String
Coding
- Reverse Degree of a String
Coding
- Reverse String
Coding · String · Two Pointers
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 345. Reverse Vowels of a String
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source