Skip to content
Decoder

Maximum Number of Vowels in a Substring of Given Length

Medium

Problem

Given a lowercase string s and an integer k, return the most vowels found in any substring of length `k`. The vowels are a, e, i, o and u.

Example 1

Input
s = "abciiidef", k = 3
Output
3
Why
"iii"

Example 2

Input
s = "leetcode", k = 3
Output
2
Why
"lee", "eet" or "ode"

Example 3

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

Constraints

  • 1 <= s.length <= 10^5
  • s consists of lowercase English letters.
  • 1 <= k <= s.length

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.