Search⌘ K
AI Features

Solution: Reverse Vowels of a String

Explore the two pointers technique to reverse only the vowels in a given string. Understand how to use pointers moving inward from both ends, swapping vowels while preserving other characters. This lesson helps you implement an efficient O(n) time and space solution applicable to string problems in coding interviews.

Statement

Given a string s, reverse only the vowels in the string and return the resulting string.

The vowels are ‘a’‘e’‘i’‘o’, and ‘u’, and they can appear in both lowercase and uppercase, potentially more than once.

Constraints:

  • 11 \leq s.length 3×105 ...