170. Vowel-Rich Window

A lighthouse keeper logs the day's radio chatter as a lowercase string s. To find the clearest stretch of speech, she measures the vowel richness of a stretch: how many of its characters are one of a, e, i, o or u.

Given s and an integer k, look at every substring made of exactly k consecutive characters and return the largest vowel richness among them. A stretch may contain no vowels at all, in which case its richness is 0.

Example 1

Input:
s = "quietsea", k = 3
Output:
3
Explanation:

The windows are qui (2), uie (3), iet (2), ets (1), tse (1) and sea (2). The best is uie with 3 vowels.

Example 2

Input:
s = "rhythm", k = 2
Output:
0
Explanation:

No window contains a vowel, so the answer is 0.

Constraints

1 ≤ k ≤ s.length ≤ 105

s consists of lowercase English letters.

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(n)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…