Problem 318805 · easy · Phase 03 Linear Management & Searching

Vowel-Rich Chant

sliding window · fixed-size window · strings

A chant is a lowercase string s. Its most melodic segment is the block of exactly k consecutive letters containing the most vowels (a, e, i, o, u). Return that maximum vowel count.

Examples

Input:  s = "abciiidef", k = 3
Output: 3
Explanation: "iii" contains three vowels.

Input:  s = "education", k = 3
Output: 2

Input:  s = "rhythms", k = 4
Output: 0

Constraints

  • 1 <= k <= len(s) <= 10**5
  • s consists of lowercase English letters.
  • Target complexity: O(n) time; counting vowels from scratch for every window is too slow for the largest tests.

Goals

  • Count a property inside a fixed window incrementally
  • Handle the entering and leaving characters symmetrically
Starting Python…