Substrings Made Only of Vowels
Updated
Problem statement
You are given a string s of lowercase English letters. The vowels are a, e, i, o and u; every other letter, including y, is a consonant.
A substring is a run of one or more consecutive letters of s. Return the number of substrings that are made only of vowels.
Substrings are counted by their position: two equal substrings that start at different places in s count as two.
Function
countVowelOnlySubstrings(s: String) → intExamples
Example 1
s = "beautiful"return = 8The vowel letters form the blocks "eau", "i" and "u". The block "eau" gives 6 substrings: "e", "a", "u", "ea", "au" and "eau". The blocks "i" and "u" give 1 each. The total is 6 + 1 + 1 = 8.
Example 2
s = "rhythm"return = 0The string has no vowels (the letter y is not a vowel here), so no substring is made only of vowels.
Example 3
s = "queueing"return = 15The only vowel block is "ueuei", 5 letters long. It has 5 substrings of length 1, 4 of length 2, 3 of length 3, 2 of length 4 and 1 of length 5, so the answer is 5 + 4 + 3 + 2 + 1 = 15. Equal substrings at different places, such as the two "ue", are counted separately.
Constraints
1 <= s.length <= 5000scontains only lowercase English letters.
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Convert Hexadecimal to Dotted IPv4Microsoft · ONSITE INTERVIEWMicrosoft interview questions
- Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
- Caesar Cipher with a Precomputed AlphabetAmazon · ONSITE INTERVIEW
- Add Two Binary StringsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Most Cost-Effective MachineCapital One · ONSITE INTERVIEWCapital One interview questions
- Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
- Iterate Canonical IPv6 AddressesOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Nth Staged License PlateGoogle · ONSITE INTERVIEWGoogle interview questions
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)