Skip to content
Decoder

Reverse Vowels of a String

Easy

Problem

Given a string s, reverse only the vowels and return the result. Every other character stays where it is. The vowels are a, e, i, o, u, in lowercase and uppercase.

Example 1

Input
s = "IceCreAm"
Output
"AceCreIm"

Example 2

Input
s = "leetcode"
Output
"leotcede"

Example 3

Input
s = "hello world"
Output
"hollo werld"

Constraints

  • 1 <= s.length <= 3 * 10^5
  • s consists of printable ASCII characters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.