Reverse Vowels of a String
Given a string s containing lowercase English letters, return a new string in which the vowels appear in reverse order. Every consonant must remain at its…
Given a string `s` containing lowercase English letters, return a new string in which the vowels appear in reverse order. Every consonant must remain at its original index. The vowels are `a`, `e`, `i`, `o`, and `u`. Indexing is 0-based.
- `1 <= s.length <= 1000` - `s` consists only of lowercase English letters. - The interactive visualizer accepts at most 20 characters. - Consonants keep their original positions; only vowels exchange positions.
Example 1: input s = "hello"; output "holle". The vowels e and o trade positions while h, l, and l stay fixed.
Example 2: input s = "leetcode"; output "leotcede". Reading the vowels e, e, o, e backwards gives e, o, e, e in the same four vowel slots.
Example 3: input s = "rhythm"; output "rhythm". There are no vowels to reverse, so the string is unchanged.
Category: Strings. Topic: strings. Difficulty: Easy. Patterns: two-pointers.