Count of Substrings Containing Every Vowel and K Consonants II — Algorithm Visualization & Coding Challenge

Choose Your Learning Path

How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.

🧠 Active Learning

Visualize the algorithm step-by-step with interactive animations in real time.

📖 Passive Learning

Read the full explanation, examples, and starter code at your own pace.

🎯 Challenge Mode

Drag and arrange the algorithm steps in the correct execution order.

🧠 Select Active to activate

JUMP INTO VISUALIZATION
Watch algorithms run step by step.

Follow every state change, comparison, and transformation as the execution unfolds in real time.

📖 Select Passive to activate

Understanding Count of Substrings Containing Every Vowel and K Consonants II
Detailed explanation and reference materials
Problem Overview

Count of Substrings Containing Every Vowel and K Consonants II

Problem Statement

Given a string word and a non-negative integer k, return the total number of substrings of word that satisfy both of the following conditions:

  • Contain every vowel ('a', 'e', 'i', 'o', and 'u') at least once.
  • Contain exactly k consonants.

Explanation

The task is to count all contiguous substrings of the input string word that:

  • Include all the vowels: a, e, i, o, and u.
  • Have exactly k consonants (letters that are not vowels).

Constraints

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

Examples

Example 1

  • Input: word = "cuaeio", k = 1
  • Explanation:
    The only valid substring is "cuaeio". It contains all vowels (u, a, e, i, o) and exactly 1 consonant (c).
  • Output: 1

Example 2

  • Input: word = "aeioubt", k = 2
  • Explanation:
    The substring "aeioubt" has all vowels and exactly 2 consonants (b and t). No other substring meets the criteria.
  • Output: 1

Example 3

  • Input: word = "abaeiou", k = 1
  • Explanation:
    There are two valid substrings:
    • "baeiou" (from index 1 to 6) contains vowels (a, e, i, o, u) and 1 consonant (b).
    • "abaeiou" (from index 0 to 6) also contains all vowels and exactly 1 consonant (b).
  • Output: 2

Constraints

  • 5<=word.length<=21055 <= word.length <= 2 * 10^5
  • word consists only of lowercase English letters.
  • 0<=k<=word.length5 0 <= k <= word.length - 5
— Written by Saurabh Patil • B.Tech CSE • Software Developer

Categories
heaps-&-hashing
leetcode-problem-of-the-day
java
Reference Link
https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/description/

Loading component...

Starter Code
Test, modify, or copy the starter code. Click "Visualize" to import into the canvas.
Java
Output:
Understood Algorithm, Test Me now 🎮

🎯 Select Challenge to activate

🧠 Logic Puzzle
Think & Arrange, Don't Just Copy-Paste

Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.

Arrange the Algorithm Correctly 🧩

The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.

Understand Below Algorithm

Don't Know Current Algorithm ?  

Green text means the instruction is placed in the correct position.

Red text means the instruction is in the wrong position.

Block Colors

Instructions with the same background color indicate particular blocks start and end.

A tick mark means the instruction is correct and locked.

🔒 Locked steps cannot be moved. Only unlocked steps are draggable.

🔊 Enable sound for swap feedback and completion effects.

DrawToCode — Visualize, Practice & Master Algorithms

Learn data structures and algorithms through interactive visualizations. Practice coding problems, track your progress, and understand concepts deeply.

EmailLinkedInTwitterInstagramGitHub
© 2026 DrawToCode. All rights reserved.