Most Vowels in a Fixed-Length Substring

Quick Overview

Most Vowels in a Fixed-Length Substring. Return the largest number of vowel occurrences in any contiguous length-k substring of s.

Most Vowels in a Fixed-Length Substring

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return the largest number of vowel occurrences in any contiguous length-k substring of s. The vowels are exactly a,e,i,o,u. ```cpp class Solution { public: int maxVowels(string s, int k); }; ``` ### Examples **Example 1:** ```text Input: s = "bace", k = 3 Output: 2 Explanation: The window ace contains a and e. ``` **Example 2:** ```text Input: s = "xyz", k = 2 Output: 0 Explanation: Neither length2 window contains a vowel. ``` ### Constraints - s contains 1 to 100000 lowercase English letters. - `1 <= k <= s.length`. ### Contract considerations Only lowercase English letters occur, and y is not a vowel. ```hint Read the boundary condition Count vowel occurrences rather than distinct vowel letters. Every candidate substring has exactly the requested length. ``` ### Boundary reminders Only lowercase English letters occur, and y is not a vowel.

Overview: Most Vowels in a Fixed-Length Substring. Return the largest number of vowel occurrences in any contiguous length-k substring of s.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the largest number of vowel occurrences in any contiguous length-k substring of s. The vowels are exactly a,e,i,o,u.

class Solution {
public:
    int maxVowels(string s, int k);
};

Examples

Example 1:

Input: s = "bace", k = 3
Output: 2
Explanation: The window ace contains a and e.

Example 2:

Input: s = "xyz", k = 2
Output: 0
Explanation: Neither length2 window contains a vowel.

Constraints

  • s contains 1 to 100000 lowercase English letters.
  • 1 <= k <= s.length .

Contract considerations

Only lowercase English letters occur, and y is not a vowel.

Boundary reminders

Only lowercase English letters occur, and y is not a vowel.