Ctrl K

Vowel-Richest Window

Medium
You are given a string text of lowercase English letters and an integer width. Look at every substring of length exactly width (consecutive characters) and return the largest number of vowels any one of them contains. The vowels are a, e, i, o and u.
Example 1
text="sequoia", width=4 → 4

The window "uoia" is made entirely of vowels, which gives 4.

Example 2
text="strength", width=3 → 1

Windows like "ren" contain at most one vowel.

Example 3
text="queue", width=5 → 4
Constraints
  • 1 ≤ len(text) ≤ 10⁵
  • text consists of lowercase English letters
  • 1 ≤ width ≤ len(text)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Repeat-Free Stretch MediumTwo-Letter Stretch MediumRecurring Gene Windows MediumWindow with Few Kinds of Letters MediumEvery Letter at Least k Times Medium
loading Python…
Input
text="sequoia", width=4
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.