Skip to main content
LeetCode 3306, Medium. Topics: Hash Table, String, Sliding Window. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 26 parametrized pytest cases, and a playground notebook:

Problem

You are given a string <code>word</code> and a <strong>non-negative</strong> integer <code>k</code>. Return the total number of <span data-keyword=“substring-nonempty”>substrings</span> of <code>word</code> that contain every vowel (<code>‘a’</code>, <code>‘e’</code>, <code>‘i’</code>, <code>‘o’</code>, and <code>‘u’</code>) <strong>at least</strong> once and <strong>exactly</strong> <code>k</code> consonants.

Examples

Constraints

  • 5 <= word.length <= 2 * 10^5
  • word consists only of lowercase English letters.
  • 0 <= k <= word.length - 5

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026