Maximum Number of Vowels in a Substring of Given Length

Given a string `s` and an integer `k`, return the maximum number of vowel letters in any substring of `s` with length `k`. Vowel letters in English are `a`, `e`, `i`, `o` and `u`.

30:00

Maximum Number of Vowels in a Substring of Given Length
medium
Free written solution
Topics
Companies

Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.

Vowel letters in English are a, e, i, o and u.

Example 1:
Input: {"s":"abciiidef","k":3}
Output: 3
Constraints:
  • 1≤s.length≤1051 \leq \text{s.length} \leq 10^5

  • ss consists of lowercase English letters.

  • 1≤k≤s.length1 \leq k \leq \text{s.length}

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"abciiidef","k":3}

Every candidate has length 3, so one frame of width 3 slides across the string. First count the vowels in the opening window.

k = 3

a
b
c
i
i
i
d
e
f

0

1

2

3

4

5

6

7

8

vowels in window: 0 of 3

vowels per window start

count

0

best

0

Variables
VariableValue
k3
n9
DepthFunction Call
Stack empty
0/17