Maximum Number of Vowels in a Substring of Given Length

Medium Topics Company Tags

Among all contiguous substrings of s with exactly k characters, return the largest number of vowels in any one substring. The vowels are a, e, i, o, and u.

Example 1:

Input: s = "buaex"
k = 3

Output: 3

Explanation: The substring "uae" contains three vowels. A substring of length 3 cannot contain more than three, so this is optimal.

Example 2:

Input: s = "rhythms"
k = 4

Output: 0

Explanation: None of these letters is a vowel. Every length-4 substring contains zero vowels.

Example 3:

Input: s = "abaca"
k = 5

Output: 3

Explanation: The only length-5 substring is the entire string "abaca". Its three occurrences of a are vowels.

Constraints:

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


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.