Reverse Vowels of a String
Problem Statement
You are given a string s.
Reverse the order of only the vowels in it, and leave every other character exactly where it is. Return the new string.
The vowels are a, e, i, o, u, in lowercase or uppercase.
A string s of printable ASCII characters.
The string with its vowels in reverse order and all other characters unchanged.
The vowels, in order, are I, e, e, A. Reversed they are A, e, e, I. Put them back into the vowel slots: "AceCreIm".
Vowels e, e, o, e become e, o, e, e.
- β’ 1 β€ s.length β€ 3 Β· 10^5
- β’ s consists of printable ASCII characters.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Copy vowels to a list, then refill the vowel slots from the end of the list
Each side skips non-vowels; swap when both stop on a vowel
Walk through s and copy every vowel into a separate string. Then walk through s again. Every time you hit a vowel slot, write in the next vowel from the end of the list.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Two Pointers translate into production architectures and low-level memory mechanics.
Circular Buffer & Ring Queue
Two pointer read/write head synchronization in production memory pools.
Pointers vs References Deep Dive
Pointer arithmetic, dereferencing semantics, and memory layout behind in-place array passes.
const Correctness & East-Const
Passing read-only spans with const int* without copying buffers.