Reverse Vowels of a String
Updated
Problem statement
Given a string s, reverse only its vowel characters and return the resulting string.
The vowels are a, e, i, o, and u, in either lowercase or uppercase. Preserve every vowel's original character and case while reversing their order. Every non-vowel character remains at its original index.
The string may be large, so avoid repeated string rebuilding that takes quadratic time.
Function
reverseVowels(s: String) → StringExamples
Example 1
s = "hello"return = "holle"The vowels are e and o. Reversing them produces holle.
Example 2
s = "leetcode"return = "leotcede"The vowel sequence e, e, o, e becomes e, o, e, e; consonants keep their positions.
Example 3
s = "aA"return = "Aa"Uppercase and lowercase vowels both participate, and their original cases move with the characters.
Constraints
0 <= s.length <= 10^6.scontains printable ASCII characters.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
- Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
- Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
- Valid Palindrome After NormalizationKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Count Binary SubstringsDocuSign · ONSITE INTERVIEWDocuSign interview questions
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
- Reverse A StringNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Validate a Word AbbreviationSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Run-Length String CompressionOracle · ONSITE INTERVIEWOracle interview questions