Reverse Vowels of a String

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Reverse Vowels of a String

Approach

Use two pointers that move toward each other from both ends. Advance each pointer until it finds a vowel, then swap the vowels and continue inward.

Complexity Analysis

Time
O(n)
Space
O(n)

Pattern

Two Pointers (Converging)

Why It Works

Converging pointers ensure each vowel pair is swapped exactly once while non-vowels are skipped and left untouched.

Updated Feb 2026