Skip to the code
cf.
+10 XP

#129 Most Vowels in a Snippet

easy

A text-to-speech preview plays a snippet of exactly k characters from a caption text. Snippets with more vowels sound smoother, so the preview picks the one with the most.

Write mostVowels(text, k) that returns the largest number of vowels (a, e, i, o, u, lowercase only) in any k consecutive characters of text. k is never more than text.length.

Example 1

Input: text = "hello world", k = 3
Output: 1

No 3 characters in a row hold more than one vowel.

Example 2

Input: text = "queue", k = 4
Output: 4

ueue has four vowels.

Constraints

  • 1 <= k <= text.length <= 100000
  • text contains lowercase letters and spaces.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).